home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 4: GNU Archives / Linux Cubed Series 4 - GNU Archives.iso / gnu / binutils.7 / binutils / binutils-2.7 / gas / config / tc-arm.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-04  |  91.7 KB  |  4,230 lines

  1. /* tc-arm.c  All the arm specific stuff in one convenient, huge,
  2.    slow to compile, easy to find file.
  3.    Contributed by Richard Earnshaw (rwe@pegasus.esprit.ec.org)
  4.     Modified by David Taylor (dtaylor@armltd.co.uk)
  5.  
  6.    Copyright (C) 1994, 1995 Free Software Foundation, Inc.
  7.  
  8.    This file is part of GAS, the GNU Assembler.
  9.  
  10.    GAS is free software; you can redistribute it and/or modify
  11.    it under the terms of the GNU General Public License as published by
  12.    the Free Software Foundation; either version 2, or (at your option)
  13.    any later version.
  14.  
  15.    GAS is distributed in the hope that it will be useful,
  16.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18.    GNU General Public License for more details.
  19.  
  20.    You should have received a copy of the GNU General Public License
  21.    along with GAS; see the file COPYING.  If not, write to
  22.    the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
  23.  
  24. #include <ctype.h>
  25. #include <string.h>
  26. #define  NO_RELOC 0
  27. #include "as.h"
  28.  
  29. /* need TARGET_CPU */
  30. #include "config.h"
  31. #include "subsegs.h"
  32. #include "obstack.h"
  33. #include "symbols.h"
  34. #include "listing.h"
  35.  
  36. /* ??? This is currently unused.  */
  37. #ifdef __STDC__
  38. #define internalError() \
  39.   as_fatal ("ARM Internal Error, line %d, %s", __LINE__, __FILE__)
  40. #else
  41. #define internalError() as_fatal ("ARM Internal Error")
  42. #endif
  43.  
  44. /* Types of processor to assemble for.  */
  45. #define ARM_1        0x00000001
  46. #define ARM_2        0x00000002
  47. #define ARM_250        0x00000002    /* Checkme, should this be = ARM_3?  */
  48. #define ARM_3        0x00000004
  49. #define ARM_6        0x00000008
  50. #define ARM_7        0x00000008
  51. #define ARM_7DM        0x00000010
  52.  
  53. /* Some useful combinations:  */
  54. #define ARM_ANY        0x00ffffff
  55. #define ARM_2UP        0x00fffffe
  56. #define ARM_ALL        ARM_2UP        /* Not arm1 only */
  57. #define ARM_3UP        0x00fffffc
  58. #define ARM_6UP        0x00fffff8
  59. #define ARM_LONGMUL    0x00000010    /* Don't know which will have this.  */
  60.  
  61. #define FPU_CORE    0x80000000
  62. #define FPU_FPA10    0x40000000
  63. #define FPU_FPA11    0x40000000
  64. #define FPU_NONE    0
  65.  
  66. /* Some useful combinations  */
  67. #define FPU_ALL        0xff000000    /* Note this is ~ARM_ANY */
  68. #define FPU_MEMMULTI    0x7f000000    /* Not fpu_core */
  69.  
  70. #ifndef CPU_DEFAULT
  71. #define CPU_DEFAULT ARM_ALL
  72. #endif
  73.  
  74. #ifndef FPU_DEFAULT
  75. #define FPU_DEFAULT FPU_ALL
  76. #endif
  77.  
  78. unsigned long cpu_variant = CPU_DEFAULT | FPU_DEFAULT;
  79.  
  80. /* This array holds the chars that always start a comment.  If the
  81.    pre-processor is disabled, these aren't very useful */
  82. CONST char comment_chars[] = "@";
  83.  
  84. /* This array holds the chars that only start a comment at the beginning of
  85.    a line.  If the line seems to have the form '# 123 filename'
  86.    .line and .file directives will appear in the pre-processed output */
  87. /* Note that input_file.c hand checks for '#' at the beginning of the
  88.    first line of the input file.  This is because the compiler outputs
  89.    #NO_APP at the beginning of its output. */
  90. /* Also note that comments like this one will always work. */
  91. CONST char line_comment_chars[] = "#";
  92.  
  93. CONST char line_separator_chars[] = "";
  94.  
  95. /* Chars that can be used to separate mant from exp in floating point nums */
  96. CONST char EXP_CHARS[] = "eE";
  97.  
  98. /* Chars that mean this number is a floating point constant */
  99. /* As in 0f12.456 */
  100. /* or    0d1.2345e12 */
  101.  
  102. CONST char FLT_CHARS[] = "rRsSfFdDxXeEpP";
  103.  
  104. const int md_reloc_size = 8;        /* Size of relocation record */
  105.  
  106. struct arm_it
  107. {
  108.   CONST char *error;
  109.   unsigned long instruction;
  110.   int suffix;
  111.   struct
  112.     {
  113.       bfd_reloc_code_real_type type;
  114.       expressionS exp;
  115.       int pc_rel;
  116.     } reloc;
  117. };
  118.  
  119. struct arm_it inst;
  120.  
  121. struct asm_shift
  122. {
  123.   CONST char *template;
  124.   unsigned long value;
  125. };
  126.  
  127. static CONST struct asm_shift shift[] =
  128. {
  129.   {"asl", 0},
  130.   {"lsl", 0},
  131.   {"lsr", 0x00000020},
  132.   {"asr", 0x00000040},
  133.   {"ror", 0x00000060},
  134.   {"rrx", 0x00000060},
  135.   {"ASL", 0},
  136.   {"LSL", 0},
  137.   {"LSR", 0x00000020},
  138.   {"ASR", 0x00000040},
  139.   {"ROR", 0x00000060},
  140.   {"RRX", 0x00000060}
  141. };
  142.  
  143. #define NO_SHIFT_RESTRICT 1
  144. #define SHIFT_RESTRICT      0
  145.  
  146. #define NUM_FLOAT_VALS 8
  147.  
  148. CONST char *fp_const[] = 
  149. {
  150.   "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
  151. };
  152.  
  153. /* Number of littlenums required to hold an extended precision number */
  154. #define MAX_LITTLENUMS 6
  155.  
  156. LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
  157.  
  158. #define FAIL    (-1)
  159. #define SUCCESS (0)
  160.  
  161. #define SUFF_S 1
  162. #define SUFF_D 2
  163. #define SUFF_E 3
  164. #define SUFF_P 4
  165.  
  166. #define CP_T_X   0x00008000
  167. #define CP_T_Y   0x00400000
  168. #define CP_T_Pre 0x01000000
  169. #define CP_T_UD  0x00800000
  170. #define CP_T_WB  0x00200000
  171.  
  172. #define TRANS_BIT    (0x00200000)
  173.  
  174. struct asm_cond
  175. {
  176.   CONST char *template;
  177.   unsigned long value;
  178. };
  179.  
  180. /* This is to save a hash look-up in the common case */
  181. #define COND_ALWAYS 0xe0000000
  182.  
  183. static CONST struct asm_cond conds[] = 
  184. {
  185.   {"eq", 0x00000000},
  186.   {"ne", 0x10000000},
  187.   {"cs", 0x20000000}, {"hs", 0x20000000},
  188.   {"cc", 0x30000000}, {"ul", 0x30000000}, {"lo", 0x30000000},
  189.   {"mi", 0x40000000},
  190.   {"pl", 0x50000000},
  191.   {"vs", 0x60000000},
  192.   {"vc", 0x70000000},
  193.   {"hi", 0x80000000},
  194.   {"ls", 0x90000000},
  195.   {"ge", 0xa0000000},
  196.   {"lt", 0xb0000000},
  197.   {"gt", 0xc0000000},
  198.   {"le", 0xd0000000},
  199.   {"al", 0xe0000000},
  200.   {"nv", 0xf0000000}
  201. };
  202.  
  203.  
  204. struct asm_flg
  205. {
  206.   CONST char *template;        /* Basic flag string */
  207.   unsigned long set_bits;    /* Bits to set */
  208. };
  209.  
  210. static CONST struct asm_flg s_flag[] =
  211. {
  212.   {"s", 0x00100000},
  213.   {NULL, 0}
  214. };
  215.  
  216. static CONST struct asm_flg ldst_flags[] =
  217. {
  218.   {"b",  0x00400000},
  219.   {"t",  TRANS_BIT},
  220.   {"bt", 0x00400000 | TRANS_BIT},
  221.   {NULL, 0}
  222. };
  223.  
  224. static CONST struct asm_flg byte_flag[] =
  225. {
  226.   {"b", 0x00400000},
  227.   {NULL, 0}
  228. };
  229.  
  230. static CONST struct asm_flg cmp_flags[] =
  231. {
  232.   {"s", 0x00100000},
  233.   {"p", 0x0010f000},
  234.   {NULL, 0}
  235. };
  236.  
  237. static CONST struct asm_flg ldm_flags[] =
  238. {
  239.   {"ed", 0x01800000},
  240.   {"fd", 0x00800000},
  241.   {"ea", 0x01000000},
  242.   {"fa", 0x08000000},
  243.   {"ib", 0x01800000},
  244.   {"ia", 0x00800000},
  245.   {"db", 0x01000000},
  246.   {"da", 0x08000000},
  247.   {NULL, 0}
  248. };
  249.  
  250. static CONST struct asm_flg stm_flags[] =
  251. {
  252.   {"ed", 0x08000000},
  253.   {"fd", 0x01000000},
  254.   {"ea", 0x00800000},
  255.   {"fa", 0x01800000},
  256.   {"ib", 0x01800000},
  257.   {"ia", 0x00800000},
  258.   {"db", 0x01000000},
  259.   {"da", 0x08000000},
  260.   {NULL, 0}
  261. };
  262.  
  263. static CONST struct asm_flg lfm_flags[] =
  264. {
  265.   {"fd", 0x00800000},
  266.   {"ea", 0x01000000},
  267.   {NULL, 0}
  268. };
  269.  
  270. static CONST struct asm_flg sfm_flags[] =
  271. {
  272.   {"fd", 0x01000000},
  273.   {"ea", 0x00800000},
  274.   {NULL, 0}
  275. };
  276.  
  277. static CONST struct asm_flg round_flags[] =
  278. {
  279.   {"p", 0x00000020},
  280.   {"m", 0x00000040},
  281.   {"z", 0x00000060},
  282.   {NULL, 0}
  283. };
  284.  
  285. static CONST struct asm_flg except_flag[] =
  286. {
  287.   {"e", 0x00400000},
  288.   {NULL, 0}
  289. };
  290.  
  291. static CONST struct asm_flg cplong_flag[] =
  292. {
  293.   {"l", 0x00400000},
  294.   {NULL, 0}
  295. };
  296.  
  297. struct asm_psr
  298. {
  299.   CONST char *template;
  300.   unsigned long number;
  301. };
  302.  
  303. #define PSR_ALL        0x00010000
  304.  
  305. static CONST struct asm_psr psrs[] =
  306. {
  307.   /* Valid <psr>'s */
  308.   {"cpsr",    0},
  309.   {"cpsr_all",    0},
  310.   {"spsr",    1},
  311.   {"spsr_all",    1},
  312.  
  313.   /* Valid <psrf>'s */
  314.   {"cpsr_flg",    2},
  315.   {"spsr_flg",    3}
  316. };
  317.  
  318. /* Functions called by parser */
  319. /* ARM instructions */
  320. static void do_arit        PARAMS ((char *operands, unsigned long flags));
  321. static void do_cmp        PARAMS ((char *operands, unsigned long flags));
  322. static void do_mov        PARAMS ((char *operands, unsigned long flags));
  323. static void do_ldst        PARAMS ((char *operands, unsigned long flags));
  324. static void do_ldmstm        PARAMS ((char *operands, unsigned long flags));
  325. static void do_branch        PARAMS ((char *operands, unsigned long flags));
  326. static void do_swi        PARAMS ((char *operands, unsigned long flags));
  327. /* Pseudo Op codes */
  328. static void do_adr        PARAMS ((char *operands, unsigned long flags));
  329. static void do_nop        PARAMS ((char *operands, unsigned long flags));
  330. /* ARM 2 */
  331. static void do_mul        PARAMS ((char *operands, unsigned long flags));
  332. static void do_mla        PARAMS ((char *operands, unsigned long flags));
  333. /* ARM 3 */
  334. static void do_swap        PARAMS ((char *operands, unsigned long flags));
  335. /* ARM 6 */
  336. static void do_msr        PARAMS ((char *operands, unsigned long flags));
  337. static void do_mrs        PARAMS ((char *operands, unsigned long flags));
  338. /* ARM 7DM */
  339. static void do_mull        PARAMS ((char *operands, unsigned long flags));
  340. /* Coprocessor Instructions */
  341. static void do_cdp        PARAMS ((char *operands, unsigned long flags));
  342. static void do_lstc        PARAMS ((char *operands, unsigned long flags));
  343. static void do_co_reg        PARAMS ((char *operands, unsigned long flags));
  344. static void do_fp_ctrl        PARAMS ((char *operands, unsigned long flags));
  345. static void do_fp_ldst        PARAMS ((char *operands, unsigned long flags));
  346. static void do_fp_ldmstm    PARAMS ((char *operands, unsigned long flags));
  347. static void do_fp_dyadic    PARAMS ((char *operands, unsigned long flags));
  348. static void do_fp_monadic    PARAMS ((char *operands, unsigned long flags));
  349. static void do_fp_cmp        PARAMS ((char *operands, unsigned long flags));
  350. static void do_fp_from_reg    PARAMS ((char *operands, unsigned long flags));
  351. static void do_fp_to_reg    PARAMS ((char *operands, unsigned long flags));
  352.  
  353. static void fix_new_arm        PARAMS ((fragS *frag, int where, 
  354.                      short int size, expressionS *exp,
  355.                      int pc_rel, int reloc));
  356. static int arm_reg_parse    PARAMS ((char **ccp));
  357. static int arm_psr_parse    PARAMS ((char **ccp));
  358.  
  359. /* All instructions take 4 bytes in the object file */
  360.  
  361. #define INSN_SIZE    4
  362.  
  363. /* LONGEST_INST is the longest basic instruction name without conditions or 
  364.  * flags.
  365.  * ARM7DM has 4 of length 5
  366.  */
  367.  
  368. #define LONGEST_INST 5
  369.  
  370. struct asm_opcode 
  371. {
  372.   CONST char *template;        /* Basic string to match */
  373.   unsigned long value;        /* Basic instruction code */
  374.   CONST char *comp_suffix;    /* Compulsory suffix that must follow conds */
  375.   CONST struct asm_flg *flags;    /* Bits to toggle if flag 'n' set */
  376.   unsigned long variants;    /* Which CPU variants this exists for */
  377.   void (*parms)();        /* Function to call to parse args */
  378. };
  379.  
  380. static CONST struct asm_opcode insns[] = 
  381. {
  382. /* ARM Instructions */
  383.   {"and",   0x00000000, NULL,   s_flag,      ARM_ANY,      do_arit},
  384.   {"eor",   0x00200000, NULL,   s_flag,      ARM_ANY,      do_arit},
  385.   {"sub",   0x00400000, NULL,   s_flag,      ARM_ANY,      do_arit},
  386.   {"rsb",   0x00600000, NULL,   s_flag,      ARM_ANY,      do_arit},
  387.   {"add",   0x00800000, NULL,   s_flag,      ARM_ANY,      do_arit},
  388.   {"adc",   0x00a00000, NULL,   s_flag,      ARM_ANY,      do_arit},
  389.   {"sbc",   0x00c00000, NULL,   s_flag,      ARM_ANY,      do_arit},
  390.   {"rsc",   0x00e00000, NULL,   s_flag,      ARM_ANY,      do_arit},
  391.   {"orr",   0x01800000, NULL,   s_flag,      ARM_ANY,      do_arit},
  392.   {"bic",   0x01c00000, NULL,   s_flag,      ARM_ANY,      do_arit},
  393.   {"tst",   0x01000000, NULL,   cmp_flags,   ARM_ANY,      do_cmp},
  394.   {"teq",   0x01200000, NULL,   cmp_flags,   ARM_ANY,      do_cmp},
  395.   {"cmp",   0x01400000, NULL,   cmp_flags,   ARM_ANY,      do_cmp},
  396.   {"cmn",   0x01600000, NULL,   cmp_flags,   ARM_ANY,      do_cmp},
  397.   {"mov",   0x01a00000, NULL,   s_flag,      ARM_ANY,      do_mov},
  398.   {"mvn",   0x01e00000, NULL,   s_flag,      ARM_ANY,      do_mov},
  399.   {"str",   0x04000000, NULL,   ldst_flags,  ARM_ANY,      do_ldst},
  400.   {"ldr",   0x04100000, NULL,   ldst_flags,  ARM_ANY,      do_ldst},
  401.   {"stm",   0x08000000, NULL,   stm_flags,   ARM_ANY,      do_ldmstm},
  402.   {"ldm",   0x08100000, NULL,   ldm_flags,   ARM_ANY,      do_ldmstm},
  403.   {"swi",   0x0f000000, NULL,   NULL,        ARM_ANY,      do_swi},
  404.   {"bl",    0x0b000000, NULL,   NULL,        ARM_ANY,      do_branch},
  405.   {"b",     0x0a000000, NULL,   NULL,        ARM_ANY,      do_branch},
  406.  
  407. /* Pseudo ops */
  408.   {"adr",   0x028f0000, NULL,   NULL,        ARM_ANY,      do_adr},
  409.   {"nop",   0x01a00000, NULL,   NULL,        ARM_ANY,      do_nop},
  410.  
  411. /* ARM 2 multiplies */
  412.   {"mul",   0x00000090, NULL,   s_flag,      ARM_2UP,      do_mul},
  413.   {"mla",   0x00200090, NULL,   s_flag,      ARM_2UP,      do_mla},
  414.  
  415. /* ARM 3 - swp instructions */
  416.   {"swp",   0x01000090, NULL,   byte_flag,   ARM_3UP,      do_swap},
  417.  
  418. /* ARM 6 Coprocessor instructions */
  419.   {"mrs",   0x010f0000, NULL,   NULL,        ARM_6UP,      do_mrs},
  420.   {"msr",   0x0128f000, NULL,   NULL,        ARM_6UP,      do_msr},
  421.  
  422. /* ARM 7DM long multiplies - need signed/unsigned flags! */
  423.   {"smull", 0x00c00090, NULL,   s_flag,      ARM_LONGMUL,  do_mull},
  424.   {"umull", 0x00800090, NULL,   s_flag,      ARM_LONGMUL,  do_mull},
  425.   {"smlal", 0x00e00090, NULL,   s_flag,      ARM_LONGMUL,  do_mull},
  426.   {"umlal", 0x00a00090, NULL,   s_flag,      ARM_LONGMUL,  do_mull},
  427.  
  428. /* Floating point instructions */
  429.   {"wfs",   0x0e200110, NULL,   NULL,        FPU_ALL,      do_fp_ctrl},
  430.   {"rfs",   0x0e300110, NULL,   NULL,        FPU_ALL,      do_fp_ctrl},
  431.   {"wfc",   0x0e400110, NULL,   NULL,        FPU_ALL,      do_fp_ctrl},
  432.   {"rfc",   0x0e500110, NULL,   NULL,        FPU_ALL,      do_fp_ctrl},
  433.   {"ldf",   0x0c100100, "sdep", NULL,        FPU_ALL,      do_fp_ldst},
  434.   {"stf",   0x0c000100, "sdep", NULL,        FPU_ALL,      do_fp_ldst},
  435.   {"lfm",   0x0c100200, NULL,   lfm_flags,   FPU_MEMMULTI, do_fp_ldmstm},
  436.   {"sfm",   0x0c000200, NULL,   sfm_flags,   FPU_MEMMULTI, do_fp_ldmstm},
  437.   {"mvf",   0x0e008100, "sde",  round_flags, FPU_ALL,      do_fp_monadic},
  438.   {"mnf",   0x0e108100, "sde",  round_flags, FPU_ALL,      do_fp_monadic},
  439.   {"abs",   0x0e208100, "sde",  round_flags, FPU_ALL,      do_fp_monadic},
  440.   {"rnd",   0x0e308100, "sde",  round_flags, FPU_ALL,      do_fp_monadic},
  441.   {"sqt",   0x0e408100, "sde",  round_flags, FPU_ALL,      do_fp_monadic},
  442.   {"log",   0x0e508100, "sde",  round_flags, FPU_ALL,      do_fp_monadic},
  443.   {"lgn",   0x0e608100, "sde",  round_flags, FPU_ALL,      do_fp_monadic},
  444.   {"exp",   0x0e708100, "sde",  round_flags, FPU_ALL,      do_fp_monadic},
  445.   {"sin",   0x0e808100, "sde",  round_flags, FPU_ALL,      do_fp_monadic},
  446.   {"cos",   0x0e908100, "sde",  round_flags, FPU_ALL,      do_fp_monadic},
  447.   {"tan",   0x0ea08100, "sde",  round_flags, FPU_ALL,      do_fp_monadic},
  448.   {"asn",   0x0eb08100, "sde",  round_flags, FPU_ALL,      do_fp_monadic},
  449.   {"acs",   0x0ec08100, "sde",  round_flags, FPU_ALL,      do_fp_monadic},
  450.   {"atn",   0x0ed08100, "sde",  round_flags, FPU_ALL,      do_fp_monadic},
  451.   {"urd",   0x0ee08100, "sde",  round_flags, FPU_ALL,      do_fp_monadic},
  452.   {"nrm",   0x0ef08100, "sde",  round_flags, FPU_ALL,      do_fp_monadic},
  453.   {"adf",   0x0e000100, "sde",  round_flags, FPU_ALL,      do_fp_dyadic},
  454.   {"suf",   0x0e200100, "sde",  round_flags, FPU_ALL,      do_fp_dyadic},
  455.   {"rsf",   0x0e300100, "sde",  round_flags, FPU_ALL,      do_fp_dyadic},
  456.   {"muf",   0x0e100100, "sde",  round_flags, FPU_ALL,      do_fp_dyadic},
  457.   {"dvf",   0x0e400100, "sde",  round_flags, FPU_ALL,      do_fp_dyadic},
  458.   {"rdf",   0x0e500100, "sde",  round_flags, FPU_ALL,      do_fp_dyadic},
  459.   {"pow",   0x0e600100, "sde",  round_flags, FPU_ALL,      do_fp_dyadic},
  460.   {"rpw",   0x0e700100, "sde",  round_flags, FPU_ALL,      do_fp_dyadic},
  461.   {"rmf",   0x0e800100, "sde",  round_flags, FPU_ALL,      do_fp_dyadic},
  462.   {"fml",   0x0e900100, "sde",  round_flags, FPU_ALL,      do_fp_dyadic},
  463.   {"fdv",   0x0ea00100, "sde",  round_flags, FPU_ALL,      do_fp_dyadic},
  464.   {"frd",   0x0eb00100, "sde",  round_flags, FPU_ALL,      do_fp_dyadic},
  465.   {"pol",   0x0ec00100, "sde",  round_flags, FPU_ALL,      do_fp_dyadic},
  466.   {"cmf",   0x0e90f110, NULL,   except_flag, FPU_ALL,      do_fp_cmp},
  467.   {"cnf",   0x0eb0f110, NULL,   except_flag, FPU_ALL,      do_fp_cmp},
  468. /* The FPA10 data sheet suggests that the 'E' of cmfe/cnfe should not
  469.    be an optional suffix, but part of the instruction.  To be compatible,
  470.    we accept either.  */
  471.   {"cmfe",  0x0ed0f110, NULL,   NULL,        FPU_ALL,      do_fp_cmp},
  472.   {"cnfe",  0x0ef0f110, NULL,   NULL,        FPU_ALL,      do_fp_cmp},
  473.   {"flt",   0x0e000110, "sde",  round_flags, FPU_ALL,      do_fp_from_reg},
  474.   {"fix",   0x0e100110, NULL,   round_flags, FPU_ALL,      do_fp_to_reg},
  475.  
  476. /* Generic copressor instructions */
  477.   {"cdp",   0x0e000000, NULL,  NULL,         ARM_ANY,      do_cdp},
  478.   {"ldc",   0x0c100000, NULL,  cplong_flag,  ARM_ANY,      do_lstc},
  479.   {"stc",   0x0c000000, NULL,  cplong_flag,  ARM_ANY,      do_lstc},
  480.   {"mcr",   0x0e000010, NULL,  NULL,         ARM_ANY,      do_co_reg},
  481.   {"mrc",   0x0e100010, NULL,  NULL,         ARM_ANY,      do_co_reg},
  482. };
  483.  
  484. /* defines for various bits that we will want to toggle */
  485.  
  486. #define INST_IMMEDIATE    0x02000000
  487. #define OFFSET_REG    0x02000000
  488. #define SHIFT_BY_REG    0x00000010
  489. #define PRE_INDEX    0x01000000
  490. #define INDEX_UP    0x00800000
  491. #define WRITE_BACK    0x00200000
  492. #define MULTI_SET_PSR    0x00400000
  493.  
  494. #define LITERAL_MASK    0xf000f000
  495. #define COND_MASK    0xf0000000
  496. #define OPCODE_MASK    0xfe1fffff
  497. #define DATA_OP_SHIFT    21
  498.  
  499. /* Codes to distinguish the arithmetic instructions */
  500.  
  501. #define OPCODE_AND    0
  502. #define OPCODE_EOR    1
  503. #define OPCODE_SUB    2
  504. #define OPCODE_RSB    3
  505. #define OPCODE_ADD    4
  506. #define OPCODE_ADC    5
  507. #define OPCODE_SBC    6
  508. #define OPCODE_RSC    7
  509. #define OPCODE_TST    8
  510. #define OPCODE_TEQ    9
  511. #define OPCODE_CMP    10
  512. #define OPCODE_CMN    11
  513. #define OPCODE_ORR    12
  514. #define OPCODE_MOV    13
  515. #define OPCODE_BIC    14
  516. #define OPCODE_MVN    15
  517.  
  518. struct reg_entry
  519. {
  520.   CONST char *name;
  521.   int number;
  522. };
  523.  
  524. #define int_register(reg) ((reg) >= 0 && (reg) <= 15)
  525. #define cp_register(reg) ((reg) >= 32 && (reg) <= 47)
  526. #define fp_register(reg) ((reg) >= 16 && (reg) <= 23)
  527.  
  528. #define REG_PC    15
  529.  
  530. /* These are the standard names;  Users can add aliases with .req */
  531. static CONST struct reg_entry reg_table[] =
  532. {
  533.   /* Processor Register Numbers */
  534.   {"r0", 0},    {"r1", 1},    {"r2", 2},    {"r3", 3},
  535.   {"r4", 4},    {"r5", 5},    {"r6", 6},    {"r7", 7},
  536.   {"r8", 8},    {"r9", 9},    {"r10", 10},  {"r11", 11},
  537.   {"r12", 12},  {"r13", 13},  {"r14", 14},  {"r15", REG_PC},
  538.   /* APCS conventions */
  539.   {"a1", 0},    {"a2", 1},    {"a3", 2},    {"a4", 3},
  540.   {"v1", 4},    {"v2", 5},    {"v3", 6},    {"v4", 7},     {"v5", 8},
  541.   {"v6", 9},    {"sb", 9},    {"v7", 10},   {"sl", 10},
  542.   {"fp", 11},    {"ip", 12},   {"sp", 13},   {"lr", 14},    {"pc", REG_PC},
  543.   /* FP Registers */
  544.   {"f0", 16},   {"f1", 17},   {"f2", 18},   {"f3", 19},
  545.   {"f4", 20},   {"f5", 21},   {"f6", 22},   {"f7", 23},
  546.   {"c0", 32},   {"c1", 33},   {"c2", 34},   {"c3", 35},
  547.   {"c4", 36},   {"c5", 37},   {"c6", 38},   {"c7", 39},
  548.   {"c8", 40},   {"c9", 41},   {"c10", 42},  {"c11", 43},
  549.   {"c12", 44},  {"c13", 45},  {"c14", 46},  {"c15", 47},
  550.   {"cr0", 32},  {"cr1", 33},  {"cr2", 34},  {"cr3", 35},
  551.   {"cr4", 36},  {"cr5", 37},  {"cr6", 38},  {"cr7", 39},
  552.   {"cr8", 40},  {"cr9", 41},  {"cr10", 42}, {"cr11", 43},
  553.   {"cr12", 44}, {"cr13", 45}, {"cr14", 46}, {"cr15", 47},
  554.   {NULL, 0}
  555. };
  556.  
  557. static CONST char *bad_args = "Bad arguments to instruction";
  558. static CONST char *bad_pc = "r15 not allowed here";
  559.  
  560. static struct hash_control *arm_ops_hsh = NULL;
  561. static struct hash_control *arm_cond_hsh = NULL;
  562. static struct hash_control *arm_shift_hsh = NULL;
  563. static struct hash_control *arm_reg_hsh = NULL;
  564. static struct hash_control *arm_psr_hsh = NULL;
  565.  
  566. /* This table describes all the machine specific pseudo-ops the assembler
  567.    has to support.  The fields are:
  568.    pseudo-op name without dot
  569.    function to call to execute this pseudo-op
  570.    Integer arg to pass to the function
  571.    */
  572.  
  573. static void s_req PARAMS ((int));
  574. static void s_align PARAMS ((int));
  575. static void s_bss PARAMS ((int));
  576. static void s_even PARAMS ((int));
  577. static void s_ltorg PARAMS ((int));
  578.  
  579. static int my_get_expression PARAMS ((expressionS *, char **));
  580.  
  581. CONST pseudo_typeS md_pseudo_table[] =
  582. {
  583.   {"req", s_req, 0},    /* Never called becasue '.req' does not start line */
  584.   {"bss", s_bss, 0},
  585.   {"align", s_align, 0},
  586.   {"even", s_even, 0},
  587.   {"ltorg", s_ltorg, 0},
  588.   {"pool", s_ltorg, 0},
  589.   {"word", cons, 4},
  590.   {"extend", float_cons, 'x'},
  591.   {"ldouble", float_cons, 'x'},
  592.   {"packed", float_cons, 'p'},
  593.   {0, 0, 0}
  594. };
  595.  
  596. /* Stuff needed to resolve the label ambiguity
  597.    As:
  598.      ...
  599.      label:   <insn>
  600.    may differ from:
  601.      ...
  602.      label:
  603.               <insn>
  604. */
  605.  
  606. symbolS *last_label_seen;
  607.  
  608. /* Literal stuff */
  609.  
  610. #define MAX_LITERAL_POOL_SIZE 1024
  611.  
  612. typedef struct literalS
  613. {
  614.   struct expressionS  exp;
  615.   struct arm_it      *inst;
  616. } literalT;
  617.  
  618. literalT literals[MAX_LITERAL_POOL_SIZE];
  619. int next_literal_pool_place = 0; /* Next free entry in the pool */
  620. int lit_pool_num = 1; /* Next literal pool number */
  621. symbolS *current_poolP = NULL;
  622. symbolS *symbol_make_empty (); 
  623.  
  624. static int
  625. add_to_lit_pool ()
  626. {
  627.   if (current_poolP == NULL)
  628.     current_poolP = symbol_make_empty();
  629.  
  630.   if (next_literal_pool_place > MAX_LITERAL_POOL_SIZE)
  631.     {
  632.       inst.error = "Literal Pool Overflow\n";
  633.       return FAIL;
  634.     }
  635.  
  636.   literals[next_literal_pool_place].exp = inst.reloc.exp;
  637.   inst.reloc.exp.X_op = O_symbol;
  638.   inst.reloc.exp.X_add_number = (next_literal_pool_place++)*4-8;
  639.   inst.reloc.exp.X_add_symbol = current_poolP;
  640.  
  641.   return SUCCESS;
  642. }
  643.  
  644. /* Can't use symbol_new here, so have to create a symbol and them at
  645.    a later datete assign iot a value. Thats what these functions do */
  646. static void
  647. symbol_locate (symbolP, name, segment, valu, frag)
  648.      symbolS *symbolP; 
  649.      CONST char *name;        /* It is copied, the caller can modify */
  650.      segT segment;        /* Segment identifier (SEG_<something>) */
  651.      valueT valu;        /* Symbol value */
  652.      fragS *frag;        /* Associated fragment */
  653. {
  654.   unsigned int name_length;
  655.   char *preserved_copy_of_name;
  656.  
  657.   name_length = strlen (name) + 1;      /* +1 for \0 */
  658.   obstack_grow (¬es, name, name_length);
  659.   preserved_copy_of_name = obstack_finish (¬es);
  660. #ifdef STRIP_UNDERSCORE
  661.   if (preserved_copy_of_name[0] == '_')
  662.     preserved_copy_of_name++;
  663. #endif
  664.  
  665. #ifdef tc_canonicalize_symbol_name
  666.   preserved_copy_of_name =
  667.     tc_canonicalize_symbol_name (preserved_copy_of_name);
  668. #endif
  669.  
  670.   S_SET_NAME (symbolP, preserved_copy_of_name);
  671.  
  672.   S_SET_SEGMENT (symbolP, segment);
  673.   S_SET_VALUE (symbolP, valu);
  674.   symbol_clear_list_pointers(symbolP);
  675.  
  676.   symbolP->sy_frag = frag;
  677.  
  678.   /*
  679.    * Link to end of symbol chain.
  680.    */
  681.   {
  682.     extern int symbol_table_frozen;
  683.     if (symbol_table_frozen)
  684.       abort ();
  685.   }
  686.  
  687.   symbol_append (symbolP, symbol_lastP, &symbol_rootP, &symbol_lastP);
  688.  
  689.   obj_symbol_new_hook (symbolP);
  690.  
  691. #ifdef tc_symbol_new_hook
  692.   tc_symbol_new_hook (symbolP);
  693. #endif
  694.  
  695. #ifdef DEBUG_SYMS
  696.   verify_symbol_chain(symbol_rootP, symbol_lastP);
  697. #endif /* DEBUG_SYMS */
  698. }
  699.  
  700. symbolS *
  701. symbol_make_empty () 
  702. {
  703.   symbolS *symbolP; 
  704.  
  705.   symbolP = (symbolS *) obstack_alloc (¬es, sizeof (symbolS));
  706.  
  707.   /* symbol must be born in some fixed state.  This seems as good as any. */
  708.   memset (symbolP, 0, sizeof (symbolS));
  709.  
  710. #ifdef BFD_ASSEMBLER
  711.   symbolP->bsym = bfd_make_empty_symbol (stdoutput);
  712.   assert (symbolP->bsym != 0);
  713.   symbolP->bsym->udata.p = (PTR) symbolP;
  714. #endif
  715.  
  716.   return symbolP;
  717. }
  718.  
  719. /* Check that an immediate is valid, and if so, convert it to the right format
  720.  */
  721.  
  722. /* OH, for a rotate instruction in C! */
  723.  
  724. static int
  725. validate_immediate (val)
  726.      int val;
  727. {
  728.   unsigned int a = (unsigned int) val;
  729.   int i;
  730.   
  731.   /* Do the easy (and most common ones) quickly */
  732.   for (i = 0; i <= 24; i += 2)
  733.     {
  734.       if ((a & (0xff << i)) == a)
  735.     return (int) (((32 - i) & 0x1e) << 7) | ((a >> i) & 0xff);
  736.     }
  737.  
  738.   /* Now do the harder ones */
  739.   for (; i < 32; i += 2)
  740.     {
  741.       if ((a & ((0xff << i) | (0xff >> (32 - i)))) == a)
  742.     {
  743.       a = ((a >> i) & 0xff) | ((a << (32 - i)) & 0xff);
  744.       return (int) a | (((32 - i) >> 1) << 8);
  745.     }
  746.     }
  747.   return FAIL;
  748. }
  749.  
  750. static int
  751. validate_offset_imm (val)
  752.      int val;
  753. {
  754.   if (val < -4095 || val > 4095)
  755.     as_bad ("bad immediate value for offset (%d)", val);
  756.   return val;
  757. }
  758.  
  759.     
  760. static void
  761. s_req (a)
  762.      int a;
  763. {
  764.   as_bad ("Invalid syntax for .req directive.");
  765. }
  766.  
  767. static void
  768. s_bss (ignore)
  769.      int ignore;
  770. {
  771.   /* We don't support putting frags in the BSS segment, we fake it by
  772.      marking in_bss, then looking at s_skip for clues?.. */
  773.   subseg_set (bss_section, 0);
  774.   demand_empty_rest_of_line ();
  775. }
  776.  
  777. static void
  778. s_even (ignore)
  779.      int ignore;
  780. {
  781.   if (!need_pass_2)        /* Never make frag if expect extra pass. */
  782.     frag_align (1, 0);
  783.   record_alignment (now_seg, 1);
  784.   demand_empty_rest_of_line ();
  785. }
  786.  
  787. static void
  788. s_ltorg (internal)
  789.      int internal;
  790. {
  791.   int lit_count = 0;
  792.   char sym_name[20];
  793.  
  794.   if (current_poolP == NULL)
  795.     {
  796.       /* Nothing to do */
  797.       if (!internal)
  798.     as_tsktsk ("Nothing to put in the pool\n");
  799.       return;
  800.     }
  801.  
  802.   /* Align pool as you have word accesses */
  803.   /* Only make a frag if we have to ... */
  804.   if (!need_pass_2)
  805.     frag_align (2, 0);
  806.  
  807.   record_alignment (now_seg, 2);
  808.  
  809.   if (internal)
  810.     as_tsktsk ("Inserting implicit pool at change of section");
  811.  
  812.   sprintf (sym_name, "$$lit_\002%x", lit_pool_num++);
  813.  
  814.   symbol_locate (current_poolP, sym_name, now_seg,
  815.          (valueT) frag_now_fix (), frag_now);
  816.   symbol_table_insert (current_poolP);
  817.  
  818.   while (lit_count < next_literal_pool_place)
  819.     /* First output the expression in the instruction to the pool */
  820.     emit_expr (&(literals[lit_count++].exp), 4); /* .word */
  821.  
  822.   next_literal_pool_place = 0;
  823.   current_poolP = NULL;
  824. }
  825.  
  826. static void
  827. arm_align (power, fill)
  828.      int power;
  829.      int fill;
  830. {
  831.   /* Only make a frag if we HAVE to ... */
  832.   if (power && !need_pass_2)
  833.     frag_align (power, fill);
  834.  
  835.   record_alignment (now_seg, power);
  836. }
  837.  
  838. static void
  839. s_align (unused)    /* Same as s_align_ptwo but align 0 => align 2 */
  840.      int unused;
  841. {
  842.   register int temp;
  843.   register long temp_fill;
  844.   long max_alignment = 15;
  845.  
  846.   temp = get_absolute_expression ();
  847.   if (temp > max_alignment)
  848.     as_bad ("Alignment too large: %d. assumed.", temp = max_alignment);
  849.   else if (temp < 0)
  850.     {
  851.       as_bad ("Alignment negative. 0 assumed.");
  852.       temp = 0;
  853.     }
  854.  
  855.   if (*input_line_pointer == ',')
  856.     {
  857.       input_line_pointer++;
  858.       temp_fill = get_absolute_expression ();
  859.     }
  860.   else
  861.     temp_fill = 0;
  862.  
  863.   if (!temp)
  864.     temp = 2;
  865.  
  866.   /* Only make a frag if we HAVE to. . . */
  867.   if (temp && !need_pass_2)
  868.     frag_align (temp, (int) temp_fill);
  869.   demand_empty_rest_of_line ();
  870.  
  871.   record_alignment (now_seg, temp);
  872. }
  873.  
  874. static void
  875. end_of_line (str)
  876.      char *str;
  877. {
  878.   while (*str == ' ')
  879.     str++;
  880.  
  881.   if (*str != '\0')
  882.     inst.error = "Garbage following instruction";
  883. }
  884.  
  885. static int
  886. skip_past_comma (str)
  887.      char **str;
  888. {
  889.   char *p = *str, c;
  890.   int comma = 0;
  891.     
  892.   while ((c = *p) == ' ' || c == ',')
  893.     {
  894.       p++;
  895.       if (c == ',' && comma++)
  896.     return FAIL;
  897.     }
  898.  
  899.   if (c == '\0')
  900.     return FAIL;
  901.  
  902.   *str = p;
  903.   return comma ? SUCCESS : FAIL;
  904. }
  905.  
  906. /* A standard register must be given at this point.  Shift is the place to
  907.    put it in the instruction. */
  908.  
  909. static int
  910. reg_required_here (str, shift)
  911.      char **str;
  912.      int shift;
  913. {
  914.   int reg;
  915.   char *start = *str;
  916.  
  917.   if ((reg = arm_reg_parse (str)) != FAIL && int_register (reg))
  918.     {
  919.       inst.instruction |= reg << shift;
  920.       return reg;
  921.     }
  922.  
  923.   /* In the few cases where we might be able to accept something else
  924.      this error can be overridden */
  925.   inst.error = "Register expected";
  926.  
  927.   /* Restore the start point, we may have got a reg of the wrong class.  */
  928.   *str = start;
  929.   return FAIL;
  930. }
  931.  
  932. static int
  933. psr_required_here (str, shift)
  934.      char **str;
  935.      int shift;
  936. {
  937.   int psr;
  938.   char *start = *str;
  939.  
  940.   if  ((psr = arm_psr_parse (str)) != FAIL && psr < 2)
  941.     {
  942.       if (psr == 1)
  943.     inst.instruction |= 1 << shift; /* Should be bit 22 */
  944.       return psr;
  945.     }
  946.  
  947.   /* In the few cases where we might be able to accept something else
  948.      this error can be overridden */
  949.   inst.error = "<psr> expected";
  950.  
  951.   /* Restore the start point.  */
  952.   *str = start;
  953.   return FAIL;
  954. }
  955.  
  956. static int
  957. psrf_required_here (str, shift)
  958.      char **str;
  959.      int shift;
  960. {
  961.   int psrf;
  962.   char *start = *str;
  963.  
  964.   if  ((psrf = arm_psr_parse (str)) != FAIL && psrf > 1)
  965.     {
  966.       if (psrf == 1 || psrf == 3)
  967.     inst.instruction |= 1 << shift; /* Should be bit 22 */
  968.       return psrf;
  969.     }
  970.  
  971.   /* In the few cases where we might be able to accept something else
  972.      this error can be overridden */
  973.   inst.error = "<psrf> expected";
  974.  
  975.   /* Restore the start point.  */
  976.   *str = start;
  977.   return FAIL;
  978. }
  979.  
  980. static int
  981. co_proc_number (str)
  982.      char **str;
  983. {
  984.   int processor, pchar;
  985.  
  986.   while (**str == ' ')
  987.     (*str)++;
  988.  
  989.   /* The data sheet seems to imply that just a number on its own is valid
  990.      here, but the RISC iX assembler seems to accept a prefix 'p'.  We will
  991.      accept either.  */
  992.   if (**str == 'p' || **str == 'P')
  993.     (*str)++;
  994.  
  995.   pchar = *(*str)++;
  996.   if (pchar >= '0' && pchar <= '9')
  997.     {
  998.       processor = pchar - '0';
  999.       if (**str >= '0' && **str <= '9')
  1000.     {
  1001.       processor = processor * 10 + *(*str)++ - '0';
  1002.       if (processor > 15)
  1003.         {
  1004.           inst.error = "Illegal co-processor number";
  1005.           return FAIL;
  1006.         }
  1007.     }
  1008.     }
  1009.   else
  1010.     {
  1011.       inst.error = "Bad or missing co-processor number";
  1012.       return FAIL;
  1013.     }
  1014.  
  1015.   inst.instruction |= processor << 8;
  1016.   return SUCCESS;
  1017. }
  1018.  
  1019. static int
  1020. cp_opc_expr (str, where, length)
  1021.      char **str;
  1022.      int where;
  1023.      int length;
  1024. {
  1025.   expressionS expr;
  1026.  
  1027.   while (**str == ' ')
  1028.     (*str)++;
  1029.  
  1030.   memset (&expr, '\0', sizeof (expr));
  1031.  
  1032.   if (my_get_expression (&expr, str))
  1033.     return FAIL;
  1034.   if (expr.X_op != O_constant)
  1035.     {
  1036.       inst.error = "bad or missing expression";
  1037.       return FAIL;
  1038.     }
  1039.  
  1040.   if ((expr.X_add_number & ((1 << length) - 1)) != expr.X_add_number)
  1041.     {
  1042.       inst.error = "immediate co-processor expression too large";
  1043.       return FAIL;
  1044.     }
  1045.  
  1046.   inst.instruction |= expr.X_add_number << where;
  1047.   return SUCCESS;
  1048. }
  1049.  
  1050. static int
  1051. cp_reg_required_here (str, where)
  1052.      char **str;
  1053.      int where;
  1054. {
  1055.   int reg;
  1056.   char *start = *str;
  1057.  
  1058.   if ((reg = arm_reg_parse (str)) != FAIL && cp_register (reg))
  1059.     {
  1060.       reg &= 15;
  1061.       inst.instruction |= reg << where;
  1062.       return reg;
  1063.     }
  1064.  
  1065.   /* In the few cases where we might be able to accept something else
  1066.      this error can be overridden */
  1067.   inst.error = "Co-processor register expected";
  1068.  
  1069.   /* Restore the start point */
  1070.   *str = start;
  1071.   return FAIL;
  1072. }
  1073.  
  1074. static int
  1075. fp_reg_required_here (str, where)
  1076.      char **str;
  1077.      int where;
  1078. {
  1079.   int reg;
  1080.   char *start = *str;
  1081.  
  1082.   if ((reg = arm_reg_parse (str)) != FAIL && fp_register (reg))
  1083.     {
  1084.       reg &= 7;
  1085.       inst.instruction |= reg << where;
  1086.       return reg;
  1087.     }
  1088.  
  1089.   /* In the few cases where we might be able to accept something else
  1090.      this error can be overridden */
  1091.   inst.error = "Floating point register expected";
  1092.  
  1093.   /* Restore the start point */
  1094.   *str = start;
  1095.   return FAIL;
  1096. }
  1097.  
  1098. static int
  1099. cp_address_offset (str)
  1100.      char **str;
  1101. {
  1102.   int offset;
  1103.  
  1104.   while (**str == ' ')
  1105.     (*str)++;
  1106.  
  1107.   if (**str != '#')
  1108.     {
  1109.       inst.error = "immediate expression expected";
  1110.       return FAIL;
  1111.     }
  1112.  
  1113.   (*str)++;
  1114.   if (my_get_expression (&inst.reloc.exp, str))
  1115.     return FAIL;
  1116.   if (inst.reloc.exp.X_op == O_constant)
  1117.     {
  1118.       offset = inst.reloc.exp.X_add_number;
  1119.       if (offset & 3)
  1120.     {
  1121.       inst.error = "co-processor address must be word aligned";
  1122.       return FAIL;
  1123.     }
  1124.  
  1125.       if (offset > 1023 || offset < -1023)
  1126.     {
  1127.       inst.error = "offset too large";
  1128.       return FAIL;
  1129.     }
  1130.  
  1131.       if (offset >= 0)
  1132.     inst.instruction |= INDEX_UP;
  1133.       else
  1134.     offset = -offset;
  1135.  
  1136.       inst.instruction |= offset >> 2;
  1137.     }
  1138.   else
  1139.     inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM;
  1140.  
  1141.   return SUCCESS;
  1142. }
  1143.  
  1144. static int
  1145. cp_address_required_here (str)
  1146.      char **str;
  1147. {
  1148.   char *p = *str;
  1149.   int pre_inc = 0;
  1150.   int write_back = 0;
  1151.  
  1152.   if (*p == '[')
  1153.     {
  1154.       int reg;
  1155.  
  1156.       p++;
  1157.       while (*p == ' ')
  1158.     p++;
  1159.  
  1160.       if ((reg = reg_required_here (&p, 16)) == FAIL)
  1161.     {
  1162.       inst.error = "Register required";
  1163.       return FAIL;
  1164.     }
  1165.  
  1166.       while (*p == ' ')
  1167.     p++;
  1168.  
  1169.       if (*p == ']')
  1170.     {
  1171.       p++;
  1172.       if (skip_past_comma (&p) == SUCCESS)
  1173.         {
  1174.           /* [Rn], #expr */
  1175.           write_back = WRITE_BACK;
  1176.           if (reg == REG_PC)
  1177.         {
  1178.           inst.error = "pc may not be used in post-increment";
  1179.           return FAIL;
  1180.         }
  1181.  
  1182.           if (cp_address_offset (&p) == FAIL)
  1183.         return FAIL;
  1184.         }
  1185.       else
  1186.         pre_inc = PRE_INDEX | INDEX_UP;
  1187.     }
  1188.       else
  1189.     {
  1190.       /* '['Rn, #expr']'[!] */
  1191.  
  1192.       if (skip_past_comma (&p) == FAIL)
  1193.         {
  1194.           inst.error = "pre-indexed expression expected";
  1195.           return FAIL;
  1196.         }
  1197.  
  1198.       pre_inc = PRE_INDEX;
  1199.       if (cp_address_offset (&p) == FAIL)
  1200.         return FAIL;
  1201.  
  1202.       while (*p == ' ')
  1203.         p++;
  1204.  
  1205.       if (*p++ != ']')
  1206.         {
  1207.           inst.error = "missing ]";
  1208.           return FAIL;
  1209.         }
  1210.  
  1211.       while (*p == ' ')
  1212.         p++;
  1213.  
  1214.       if (*p == '!')
  1215.         {
  1216.           if (reg == REG_PC)
  1217.         {
  1218.           inst.error = "pc may not be used with write-back";
  1219.           return FAIL;
  1220.         }
  1221.  
  1222.           p++;
  1223.           write_back = WRITE_BACK;
  1224.         }
  1225.     }
  1226.     }
  1227.   else
  1228.     {
  1229.       if (my_get_expression (&inst.reloc.exp, &p))
  1230.     return FAIL;
  1231.  
  1232.       inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM;
  1233.       inst.reloc.exp.X_add_number -= 8;  /* PC rel adjust */
  1234.       inst.reloc.pc_rel = 1;
  1235.       inst.instruction |= (REG_PC << 16);
  1236.       pre_inc = PRE_INDEX;
  1237.     }
  1238.  
  1239.   inst.instruction |= write_back | pre_inc;
  1240.   *str = p;
  1241.   return SUCCESS;
  1242. }
  1243.  
  1244. static void
  1245. do_nop (str, flags)
  1246.      char *str;
  1247.      unsigned long flags;
  1248. {
  1249.   /* Do nothing really */
  1250.   inst.instruction |= flags; /* This is pointless */
  1251.   end_of_line (str);
  1252.   return;
  1253. }
  1254.  
  1255. static void
  1256. do_mrs (str, flags)
  1257.      char *str;
  1258.      unsigned long flags;
  1259. {
  1260.   /* Only one syntax */
  1261.   while (*str == ' ')
  1262.     str++;
  1263.  
  1264.   if (reg_required_here (&str, 12) == FAIL)
  1265.     {
  1266.       inst.error = bad_args;
  1267.       return;
  1268.     }
  1269.  
  1270.   if (skip_past_comma (&str) == FAIL
  1271.       || psr_required_here (&str, 22) == FAIL)
  1272.     {
  1273.       inst.error = "<psr> expected";
  1274.       return;
  1275.     }
  1276.  
  1277.   inst.instruction |= flags;
  1278.   end_of_line (str);
  1279.   return;
  1280. }
  1281.  
  1282. static void
  1283. do_msr (str, flags)
  1284.      char *str;
  1285.      unsigned long flags;
  1286. {
  1287.   int psr, psrf, reg;
  1288.   /* Three possible forms: "<psr>, Rm", "<psrf>, Rm", "<psrf>, #expression" */
  1289.  
  1290.   while (*str == ' ')
  1291.     str++;
  1292.  
  1293.   if ((psr = psr_required_here (&str, 22)) != FAIL)
  1294.     {
  1295.       inst.instruction |= PSR_ALL;
  1296.       /* Sytax should be "<psr>, Rm" */
  1297.       if (skip_past_comma (&str) == FAIL
  1298.       || (reg = reg_required_here (&str, 0)) == FAIL)
  1299.     {
  1300.       inst.error = bad_args;
  1301.       return;
  1302.     }
  1303.     }
  1304.   else if ((psrf = psrf_required_here (&str, 22)) != FAIL)
  1305.     /* Syntax could be "<psrf>, rm", "<psrf>, #expression" */
  1306.     {
  1307.       if (skip_past_comma (&str) == FAIL)
  1308.     {
  1309.       inst.error = bad_args;
  1310.       return;
  1311.     }
  1312.       if ((reg = reg_required_here (&str, 0)) != FAIL)
  1313.     ;
  1314.       /* Immediate expression */
  1315.       else if (*(str++) == '#')
  1316.     {
  1317.       inst.error = NULL;
  1318.       if (my_get_expression (&inst.reloc.exp, &str))
  1319.         {
  1320.           inst.error = "Register or shift expression expected";
  1321.           return;
  1322.         }
  1323.  
  1324.       if (inst.reloc.exp.X_add_symbol)
  1325.         {
  1326.           inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
  1327.           inst.reloc.pc_rel = 0;
  1328.         }
  1329.       else
  1330.         {
  1331.           int value = validate_immediate (inst.reloc.exp.X_add_number);
  1332.           if (value == FAIL)
  1333.         {
  1334.           inst.error = "Invalid constant";
  1335.           return;
  1336.         }
  1337.  
  1338.           inst.instruction |= value;
  1339.         }
  1340.  
  1341.       flags |= INST_IMMEDIATE;
  1342.     }
  1343.       else
  1344.     {
  1345.       inst.error = "Error: the other";
  1346.       return;
  1347.     }
  1348.     }
  1349.   else
  1350.     {
  1351.       inst.error = bad_args;
  1352.       return;
  1353.     }
  1354.      
  1355.   inst.error = NULL; 
  1356.   inst.instruction |= flags;
  1357.   end_of_line (str);
  1358.   return;
  1359. }
  1360.  
  1361. /* Long Multiply Parser
  1362.    UMULL RdLo, RdHi, Rm, Rs
  1363.    SMULL RdLo, RdHi, Rm, Rs
  1364.    UMLAL RdLo, RdHi, Rm, Rs
  1365.    SMLAL RdLo, RdHi, Rm, Rs
  1366. */   
  1367. static void
  1368. do_mull (str, flags)
  1369.      char *str;
  1370.      unsigned long flags;
  1371. {
  1372.   int rdlo, rdhi, rm, rs;
  1373.  
  1374.   /* only one format "rdlo, rdhi, rm, rs" */
  1375.   while (*str == ' ')
  1376.     str++;
  1377.  
  1378.   if ((rdlo = reg_required_here (&str, 12)) == FAIL)
  1379.     {
  1380.       inst.error = bad_args;
  1381.       return;
  1382.     }
  1383.  
  1384.   if (skip_past_comma (&str) == FAIL
  1385.       || (rdhi = reg_required_here (&str, 16)) == FAIL)
  1386.     {
  1387.       inst.error = bad_args;
  1388.       return;
  1389.     }
  1390.  
  1391.   if (skip_past_comma (&str) == FAIL
  1392.       || (rm = reg_required_here (&str, 0)) == FAIL)
  1393.     {
  1394.       inst.error = bad_args;
  1395.       return;
  1396.     }
  1397.  
  1398.   /* rdhi, rdlo and rm must all be different */
  1399.   if (rdlo == rdhi || rdlo == rm || rdhi == rm)
  1400.     as_tsktsk ("rdhi, rdlo and rm must all be different");
  1401.  
  1402.   if (skip_past_comma (&str) == FAIL
  1403.       || (rs = reg_required_here (&str, 8)) == FAIL)
  1404.     {
  1405.       inst.error = bad_args;
  1406.       return;
  1407.     }
  1408.  
  1409.   if (rdhi == REG_PC || rdhi == REG_PC || rdhi == REG_PC || rdhi == REG_PC)
  1410.     {
  1411.       inst.error = bad_pc;
  1412.       return;
  1413.     }
  1414.    
  1415.   inst.instruction |= flags;
  1416.   end_of_line (str);
  1417.   return;
  1418. }
  1419.  
  1420. static void
  1421. do_mul (str, flags)
  1422.      char *str;
  1423.      unsigned long flags;
  1424. {
  1425.   int rd, rm;
  1426.   
  1427.   /* only one format "rd, rm, rs" */
  1428.   while (*str == ' ')
  1429.     str++;
  1430.  
  1431.   if ((rd = reg_required_here (&str, 16)) == FAIL)
  1432.     {
  1433.       inst.error = bad_args;
  1434.       return;
  1435.     }
  1436.  
  1437.   if (rd == REG_PC)
  1438.     {
  1439.       inst.error = bad_pc;
  1440.       return;
  1441.     }
  1442.  
  1443.   if (skip_past_comma (&str) == FAIL
  1444.       || (rm = reg_required_here (&str, 0)) == FAIL)
  1445.     {
  1446.       inst.error = bad_args;
  1447.       return;
  1448.     }
  1449.  
  1450.   if (rm == REG_PC)
  1451.     {
  1452.       inst.error = bad_pc;
  1453.       return;
  1454.     }
  1455.  
  1456.   if (rm == rd)
  1457.     as_tsktsk ("rd and rm should be different in mul");
  1458.  
  1459.   if (skip_past_comma (&str) == FAIL
  1460.       || (rm = reg_required_here (&str, 8)) == FAIL)
  1461.     {
  1462.       inst.error = bad_args;
  1463.       return;
  1464.     }
  1465.  
  1466.   if (rm == REG_PC)
  1467.     {
  1468.       inst.error = bad_pc;
  1469.       return;
  1470.     }
  1471.  
  1472.   inst.instruction |= flags;
  1473.   end_of_line (str);
  1474.   return;
  1475. }
  1476.  
  1477. static void
  1478. do_mla (str, flags)
  1479.      char *str;
  1480.      unsigned long flags;
  1481. {
  1482.   int rd, rm;
  1483.  
  1484.   /* only one format "rd, rm, rs, rn" */
  1485.   while (*str == ' ')
  1486.     str++;
  1487.  
  1488.   if ((rd = reg_required_here (&str, 16)) == FAIL)
  1489.     {
  1490.       inst.error = bad_args;
  1491.       return;
  1492.     }
  1493.  
  1494.   if (rd == REG_PC)
  1495.     {
  1496.       inst.error = bad_pc;
  1497.       return;
  1498.     }
  1499.  
  1500.   if (skip_past_comma (&str) == FAIL
  1501.       || (rm = reg_required_here (&str, 0)) == FAIL)
  1502.     {
  1503.       inst.error = bad_args;
  1504.       return;
  1505.     }
  1506.  
  1507.   if (rm == REG_PC)
  1508.     {
  1509.       inst.error = bad_pc;
  1510.       return;
  1511.     }
  1512.  
  1513.   if (rm == rd)
  1514.     as_tsktsk ("rd and rm should be different in mla");
  1515.  
  1516.   if (skip_past_comma (&str) == FAIL
  1517.       || (rd = reg_required_here (&str, 8)) == FAIL
  1518.       || skip_past_comma (&str) == FAIL
  1519.       || (rm = reg_required_here (&str, 12)) == FAIL)
  1520.     {
  1521.       inst.error = bad_args;
  1522.       return;
  1523.     }
  1524.  
  1525.   if (rd == REG_PC || rm == REG_PC)
  1526.     {
  1527.       inst.error = bad_pc;
  1528.       return;
  1529.     }
  1530.  
  1531.   inst.instruction |= flags;
  1532.   end_of_line (str);
  1533.   return;
  1534. }
  1535.  
  1536. /* Returns the index into fp_values of a floating point number, or -1 if
  1537.    not in the table.  */
  1538. static int
  1539. my_get_float_expression (str)
  1540.      char **str;
  1541. {
  1542.   LITTLENUM_TYPE words[MAX_LITTLENUMS];
  1543.   char *save_in;
  1544.   expressionS exp;
  1545.   int i, j;
  1546.  
  1547.   memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
  1548.   /* Look for a raw floating point number */
  1549.   if ((save_in = atof_ieee (*str, 'x', words)) != NULL
  1550.       && (is_end_of_line [(int)(*save_in)] || *save_in == '\0'))
  1551.     {
  1552.       for (i = 0; i < NUM_FLOAT_VALS; i++)
  1553.     {
  1554.       for (j = 0; j < MAX_LITTLENUMS; j++)
  1555.         {
  1556.           if (words[j] != fp_values[i][j])
  1557.         break;
  1558.         }
  1559.  
  1560.       if (j == MAX_LITTLENUMS)
  1561.         {
  1562.           *str = save_in;
  1563.           return i;
  1564.         }
  1565.     }
  1566.     }
  1567.  
  1568.   /* Try and parse a more complex expression, this will probably fail
  1569.      unless the code uses a floating point prefix (eg "0f") */
  1570.   save_in = input_line_pointer;
  1571.   input_line_pointer = *str;
  1572.   if (expression (&exp) == absolute_section
  1573.       && exp.X_op == O_big
  1574.       && exp.X_add_number < 0)
  1575.     {
  1576.       /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
  1577.      Ditto for 15.  */
  1578.       if (gen_to_words (words, 5, (long)15) == 0)
  1579.     {
  1580.       for (i = 0; i < NUM_FLOAT_VALS; i++)
  1581.         {
  1582.           for (j = 0; j < MAX_LITTLENUMS; j++)
  1583.         {
  1584.           if (words[j] != fp_values[i][j])
  1585.             break;
  1586.         }
  1587.  
  1588.           if (j == MAX_LITTLENUMS)
  1589.         {
  1590.           *str = input_line_pointer;
  1591.           input_line_pointer = save_in;
  1592.           return i;
  1593.         }
  1594.         }
  1595.     }
  1596.     }
  1597.  
  1598.   *str = input_line_pointer;
  1599.   input_line_pointer = save_in;
  1600.   return -1;
  1601. }
  1602.  
  1603. /* Return true if anything in the expression is a bignum */
  1604. static int
  1605. walk_no_bignums (sp)
  1606.      symbolS *sp;
  1607. {
  1608.   if (sp->sy_value.X_op == O_big)
  1609.     return 1;
  1610.  
  1611.   if (sp->sy_value.X_add_symbol)
  1612.     {
  1613.       return (walk_no_bignums (sp->sy_value.X_add_symbol)
  1614.           || (sp->sy_value.X_op_symbol
  1615.           && walk_no_bignums (sp->sy_value.X_op_symbol)));
  1616.     }
  1617.  
  1618.   return 0;
  1619. }
  1620.  
  1621. static int
  1622. my_get_expression (ep, str)
  1623.      expressionS *ep;
  1624.      char **str;
  1625. {
  1626.   char *save_in;
  1627.   segT seg;
  1628.   
  1629.   save_in = input_line_pointer;
  1630.   input_line_pointer = *str;
  1631.   seg = expression (ep);
  1632.  
  1633. #ifdef OBJ_AOUT
  1634.   if (seg != absolute_section
  1635.       && seg != text_section
  1636.       && seg != data_section
  1637.       && seg != bss_section
  1638.       && seg != undefined_section)
  1639.     {
  1640.       inst.error = "bad_segment";
  1641.       *str = input_line_pointer;
  1642.       input_line_pointer = save_in;
  1643.       return 1;
  1644.     }
  1645. #endif
  1646.  
  1647.   /* Get rid of any bignums now, so that we don't generate an error for which
  1648.      we can't establish a line number later on.  Big numbers are never valid
  1649.      in instructions, which is where this routine is always called.  */
  1650.   if (ep->X_op == O_big
  1651.       || (ep->X_add_symbol
  1652.       && (walk_no_bignums (ep->X_add_symbol)
  1653.           || (ep->X_op_symbol
  1654.           && walk_no_bignums (ep->X_op_symbol)))))
  1655.     {
  1656.       inst.error = "Invalid constant";
  1657.       *str = input_line_pointer;
  1658.       input_line_pointer = save_in;
  1659.       return 1;
  1660.     }
  1661.  
  1662.   *str = input_line_pointer;
  1663.   input_line_pointer = save_in;
  1664.   return 0;
  1665. }
  1666.  
  1667. /* unrestrict should be one if <shift> <register> is permitted for this
  1668.    instruction */
  1669.  
  1670. static int
  1671. decode_shift (str, unrestrict)
  1672.      char **str;
  1673.      int unrestrict;
  1674. {
  1675.   struct asm_shift *shft;
  1676.   char *p;
  1677.   char c;
  1678.     
  1679.   while (**str == ' ')
  1680.     (*str)++;
  1681.     
  1682.   for (p = *str; isalpha (*p); p++)
  1683.     ;
  1684.  
  1685.   if (p == *str)
  1686.     {
  1687.       inst.error = "Shift expression expected";
  1688.       return FAIL;
  1689.     }
  1690.  
  1691.   c = *p;
  1692.   *p = '\0';
  1693.   shft = (struct asm_shift *) hash_find (arm_shift_hsh, *str);
  1694.   *p = c;
  1695.   if (shft)
  1696.     {
  1697.       if (!strcmp (*str, "rrx"))
  1698.     {
  1699.       *str = p;
  1700.       inst.instruction |= shft->value;
  1701.       return SUCCESS;
  1702.     }
  1703.  
  1704.       while (*p == ' ')
  1705.     p++;
  1706.  
  1707.       if (unrestrict && reg_required_here (&p, 8) != FAIL)
  1708.     {
  1709.       inst.instruction |= shft->value | SHIFT_BY_REG;
  1710.       *str = p;
  1711.       return SUCCESS;
  1712.     }
  1713.       else if (*p == '#')
  1714.     {
  1715.       inst.error = NULL;
  1716.       p++;
  1717.       if (my_get_expression (&inst.reloc.exp, &p))
  1718.         return FAIL;
  1719.  
  1720.       /* Validate some simple #expressions */
  1721.       if (! inst.reloc.exp.X_add_symbol)
  1722.         {
  1723.           int num = inst.reloc.exp.X_add_number;
  1724.           if (num < 0 || num > 32
  1725.           || (num == 32 
  1726.               && (shft->value == 0 || shft->value == 0x60)))
  1727.         {
  1728.           inst.error = "Invalid immediate shift";
  1729.           return FAIL;
  1730.         }
  1731.  
  1732.           /* Shifts of zero should be converted to lsl (which is zero)*/
  1733.           if (num == 0)
  1734.         {
  1735.           *str = p;
  1736.           return SUCCESS;
  1737.         }
  1738.  
  1739.           /* Shifts of 32 are encoded as 0, for those shifts that
  1740.          support it.  */
  1741.           if (num == 32)
  1742.         num = 0;
  1743.  
  1744.           inst.instruction |= (num << 7) | shft->value;
  1745.           *str = p;
  1746.           return SUCCESS;
  1747.         }
  1748.  
  1749.       inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
  1750.       inst.reloc.pc_rel = 0;
  1751.       inst.instruction |= shft->value;
  1752.       *str = p;
  1753.       return SUCCESS;
  1754.     }
  1755.       else
  1756.     {
  1757.       inst.error = unrestrict ? "shift requires register or #expression"
  1758.         : "shift requires #expression";
  1759.       *str = p;
  1760.       return FAIL;
  1761.     }
  1762.     }
  1763.  
  1764.   inst.error = "Shift expression expected";
  1765.   return FAIL;
  1766. }
  1767.  
  1768. /* Do those data_ops which can take a negative immediate constant */
  1769. /* by altering the instuction. A bit of a hack really */
  1770. /*      MOV <-> MVN
  1771.         AND <-> BIC
  1772.         ADC <-> SBC
  1773.         by inverting the second operand, and
  1774.         ADD <-> SUB
  1775.         CMP <-> CMN
  1776.         by negating the second operand.
  1777. */
  1778. static int
  1779. negate_data_op (instruction, value)
  1780.      unsigned long *instruction;
  1781.      unsigned long value;
  1782. {
  1783.   int op, new_inst;
  1784.   unsigned long negated, inverted;
  1785.  
  1786.   negated = validate_immediate (-value);
  1787.   inverted = validate_immediate (~value);
  1788.  
  1789.   op = (*instruction >> DATA_OP_SHIFT) & 0xf;
  1790.   switch (op)
  1791.     {
  1792.       /* First negates */
  1793.     case OPCODE_SUB:             /* ADD <-> SUB */
  1794.       new_inst = OPCODE_ADD;
  1795.       value = negated;
  1796.       break;
  1797.  
  1798.     case OPCODE_ADD: 
  1799.       new_inst = OPCODE_SUB;               
  1800.       value = negated;
  1801.       break;
  1802.  
  1803.     case OPCODE_CMP:             /* CMP <-> CMN */
  1804.       new_inst = OPCODE_CMN;
  1805.       value = negated;
  1806.       break;
  1807.  
  1808.     case OPCODE_CMN: 
  1809.       new_inst = OPCODE_CMP;               
  1810.       value = negated;
  1811.       break;
  1812.  
  1813.       /* Now Inverted ops */
  1814.     case OPCODE_MOV:             /* MOV <-> MVN */
  1815.       new_inst = OPCODE_MVN;               
  1816.       value = inverted;
  1817.       break;
  1818.  
  1819.     case OPCODE_MVN: 
  1820.       new_inst = OPCODE_MOV;
  1821.       value = inverted;
  1822.       break;
  1823.  
  1824.     case OPCODE_AND:             /* AND <-> BIC */ 
  1825.       new_inst = OPCODE_BIC;               
  1826.       value = inverted;
  1827.       break;
  1828.  
  1829.     case OPCODE_BIC: 
  1830.       new_inst = OPCODE_AND;
  1831.       value = inverted;
  1832.       break;
  1833.  
  1834.     case OPCODE_ADC:              /* ADC <-> SBC */
  1835.       new_inst = OPCODE_SBC;               
  1836.       value = inverted;
  1837.       break;
  1838.  
  1839.     case OPCODE_SBC: 
  1840.       new_inst = OPCODE_ADC;
  1841.       value = inverted;
  1842.       break;
  1843.  
  1844.       /* We cannot do anything */
  1845.     default:  
  1846.       return FAIL;
  1847.     }
  1848.  
  1849.   if (value == FAIL)
  1850.     return FAIL;
  1851.  
  1852.   *instruction &= OPCODE_MASK;
  1853.   *instruction |= new_inst << DATA_OP_SHIFT;
  1854.   return value; 
  1855. }
  1856.  
  1857. static int
  1858. data_op2 (str)
  1859.      char **str;
  1860. {
  1861.   int value;
  1862.   expressionS expr;
  1863.  
  1864.   while (**str == ' ')
  1865.     (*str)++;
  1866.     
  1867.   if (reg_required_here (str, 0) != FAIL)
  1868.     {
  1869.       if (skip_past_comma (str) == SUCCESS)
  1870.     {
  1871.       /* Shift operation on register */
  1872.       return decode_shift (str, NO_SHIFT_RESTRICT);
  1873.     }
  1874.       return SUCCESS;
  1875.     }
  1876.   else
  1877.     {
  1878.       /* Immediate expression */
  1879.       if (*((*str)++) == '#')
  1880.     {
  1881.       inst.error = NULL;
  1882.       if (my_get_expression (&inst.reloc.exp, str))
  1883.         return FAIL;
  1884.  
  1885.       if (inst.reloc.exp.X_add_symbol)
  1886.         {
  1887.           inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
  1888.           inst.reloc.pc_rel = 0;
  1889.         }
  1890.       else
  1891.         {
  1892.           if (skip_past_comma (str) == SUCCESS)
  1893.         {
  1894.           /* #x, y -- ie explicit rotation by Y  */
  1895.           if (my_get_expression (&expr, str))
  1896.             return FAIL;
  1897.  
  1898.           if (expr.X_op != O_constant)
  1899.             {
  1900.               inst.error = "Constant expression expected";
  1901.               return FAIL;
  1902.             }
  1903.  
  1904.           /* Rotate must be a multiple of 2 */
  1905.           if (((unsigned) expr.X_add_number) > 30
  1906.               || (expr.X_add_number & 1) != 0
  1907.               || ((unsigned) inst.reloc.exp.X_add_number) > 255)
  1908.             {
  1909.               inst.error = "Invalid constant";
  1910.               return FAIL;
  1911.             }
  1912.           inst.instruction |= INST_IMMEDIATE;
  1913.           inst.instruction |= inst.reloc.exp.X_add_number;
  1914.           inst.instruction |= expr.X_add_number << 7;
  1915.           return SUCCESS;
  1916.         }
  1917.  
  1918.           /* Implicit rotation, select a suitable one  */
  1919.           value = validate_immediate (inst.reloc.exp.X_add_number);
  1920.  
  1921.           if (value == FAIL)
  1922.         {
  1923.           /* Can't be done, perhaps the code reads something like
  1924.              "add Rd, Rn, #-n", where "sub Rd, Rn, #n" would be ok */
  1925.           if ((value = negate_data_op (&inst.instruction,
  1926.                            inst.reloc.exp.X_add_number))
  1927.               == FAIL)
  1928.             {
  1929.               inst.error = "Invalid constant";
  1930.               return FAIL;
  1931.             }
  1932.         }
  1933.  
  1934.           inst.instruction |= value;
  1935.         }
  1936.  
  1937.       inst.instruction |= INST_IMMEDIATE;
  1938.       return SUCCESS;
  1939.     }
  1940.  
  1941.       inst.error = "Register or shift expression expected";
  1942.       return FAIL;
  1943.     }
  1944. }
  1945.  
  1946. static int
  1947. fp_op2 (str, flags)
  1948.      char **str;
  1949.      unsigned long flags;
  1950. {
  1951.   while (**str == ' ')
  1952.     (*str)++;
  1953.  
  1954.   if (fp_reg_required_here (str, 0) != FAIL)
  1955.     return SUCCESS;
  1956.   else
  1957.     {
  1958.       /* Immediate expression */
  1959.       if (*((*str)++) == '#')
  1960.     {
  1961.       int i;
  1962.  
  1963.       inst.error = NULL;
  1964.       while (**str == ' ')
  1965.         (*str)++;
  1966.  
  1967.       /* First try and match exact strings, this is to guarantee that
  1968.          some formats will work even for cross assembly */
  1969.  
  1970.       for (i = 0; fp_const[i]; i++)
  1971.         {
  1972.           if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
  1973.         {
  1974.           char *start = *str;
  1975.  
  1976.           *str += strlen (fp_const[i]);
  1977.           if (is_end_of_line[(int)**str] || **str == '\0')
  1978.             {
  1979.               inst.instruction |= i + 8;
  1980.               return SUCCESS;
  1981.             }
  1982.           *str = start;
  1983.         }
  1984.         }
  1985.  
  1986.       /* Just because we didn't get a match doesn't mean that the
  1987.          constant isn't valid, just that it is in a format that we
  1988.          don't automatically recognize.  Try parsing it with
  1989.          the standard expression routines.  */
  1990.       if ((i = my_get_float_expression (str)) >= 0)
  1991.         {
  1992.           inst.instruction |= i + 8;
  1993.           return SUCCESS;
  1994.         }
  1995.  
  1996.       inst.error = "Invalid floating point immediate expression";
  1997.       return FAIL;
  1998.     }
  1999.       inst.error = "Floating point register or immediate expression expected";
  2000.       return FAIL;
  2001.     }
  2002. }
  2003.  
  2004. static void
  2005. do_arit (str, flags)
  2006.      char *str;
  2007.      unsigned long flags;
  2008. {
  2009.   while (*str == ' ')
  2010.     str++;
  2011.  
  2012.   if (reg_required_here (&str, 12) == FAIL
  2013.       || skip_past_comma (&str) == FAIL
  2014.       || reg_required_here (&str, 16) == FAIL
  2015.       || skip_past_comma (&str) == FAIL
  2016.       || data_op2 (&str) == FAIL)
  2017.     {
  2018.       if (!inst.error)
  2019.     inst.error = bad_args;
  2020.       return;
  2021.     }
  2022.  
  2023.   inst.instruction |= flags;
  2024.   end_of_line (str);
  2025.   return;
  2026. }
  2027.  
  2028. static void
  2029. do_adr (str, flags)
  2030.      char *str;
  2031.      unsigned long flags;
  2032. {
  2033.   /* This is a pseudo-op of the form "adr rd, label" to be converted into
  2034.      a relative address of the form add rd, pc, #label-.-8 */
  2035.  
  2036.   while (*str == ' ')
  2037.     str++;
  2038.  
  2039.   if (reg_required_here (&str, 12) == FAIL
  2040.       || skip_past_comma (&str) == FAIL
  2041.       || my_get_expression (&inst.reloc.exp, &str))
  2042.     {
  2043.       if (!inst.error)
  2044.     inst.error = bad_args;
  2045.       return;
  2046.     }
  2047.   /* Frag hacking will turn this into a sub instruction if the offset turns
  2048.      out to be negative.  */
  2049.   inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
  2050.   inst.reloc.exp.X_add_number -= 8; /* PC relative adjust */
  2051.   inst.reloc.pc_rel = 1;
  2052.   inst.instruction |= flags;
  2053.   end_of_line (str);
  2054.   return;
  2055. }
  2056.  
  2057. static void
  2058. do_cmp (str, flags)
  2059.      char *str;
  2060.      unsigned long flags;
  2061. {
  2062.   while (*str == ' ')
  2063.     str++;
  2064.  
  2065.   if (reg_required_here (&str, 16) == FAIL)
  2066.     {
  2067.       if (!inst.error)
  2068.     inst.error = bad_args;
  2069.       return;
  2070.     }
  2071.  
  2072.   if (skip_past_comma (&str) == FAIL
  2073.       || data_op2 (&str) == FAIL)
  2074.     {
  2075.       if (!inst.error)
  2076.     inst.error = bad_args;
  2077.       return;
  2078.     }
  2079.  
  2080.   inst.instruction |= flags;
  2081.   if ((flags & 0x0000f000) == 0)
  2082.     inst.instruction |= 0x00100000;
  2083.  
  2084.   end_of_line (str);
  2085.   return;
  2086. }
  2087.  
  2088. static void
  2089. do_mov (str, flags)
  2090.      char *str;
  2091.      unsigned long flags;
  2092. {
  2093.   while (*str == ' ')
  2094.     str++;
  2095.  
  2096.   if (reg_required_here (&str, 12) == FAIL)
  2097.     {
  2098.       if (!inst.error)
  2099.     inst.error = bad_args;
  2100.       return;
  2101.     }
  2102.  
  2103.   if (skip_past_comma (&str) == FAIL
  2104.       || data_op2 (&str) == FAIL)
  2105.     {
  2106.       if (!inst.error)
  2107.     inst.error = bad_args;
  2108.       return;
  2109.     }
  2110.  
  2111.   inst.instruction |= flags;
  2112.   end_of_line (str);
  2113.   return;
  2114. }
  2115.  
  2116. static int
  2117. ldst_extend (str)
  2118.      char **str;
  2119. {
  2120.   int add = INDEX_UP;
  2121.  
  2122.   switch (**str)
  2123.     {
  2124.     case '#':
  2125.       (*str)++;
  2126.       if (my_get_expression (&inst.reloc.exp, str))
  2127.     return FAIL;
  2128.  
  2129.       if (inst.reloc.exp.X_op == O_constant)
  2130.     {
  2131.       int value = inst.reloc.exp.X_add_number;
  2132.  
  2133.       if (value < -4095 || value > 4095)
  2134.         {
  2135.           inst.error = "address offset too large";
  2136.           return FAIL;
  2137.         }
  2138.  
  2139.       if (value < 0)
  2140.         {
  2141.           value = -value;
  2142.           add = 0;
  2143.         }
  2144.  
  2145.       inst.instruction |= add | value;
  2146.     }
  2147.       else
  2148.     {
  2149.       inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM;
  2150.       inst.reloc.pc_rel = 0;
  2151.     }
  2152.       return SUCCESS;
  2153.  
  2154.     case '-':
  2155.       add = 0;    /* and fall through */
  2156.     case '+':
  2157.       (*str)++;    /* and fall through */
  2158.     default:
  2159.       if (reg_required_here (str, 0) == FAIL)
  2160.     {
  2161.       inst.error = "Register expected";
  2162.       return FAIL;
  2163.     }
  2164.       inst.instruction |= add | OFFSET_REG;
  2165.       if (skip_past_comma (str) == SUCCESS)
  2166.     return decode_shift (str, SHIFT_RESTRICT);
  2167.       return SUCCESS;
  2168.     }
  2169. }
  2170.  
  2171. static void
  2172. do_ldst (str, flags)
  2173.      char *str;
  2174.      unsigned long flags;
  2175. {
  2176.   int pre_inc = 0;
  2177.   int conflict_reg;
  2178.   int value;
  2179.  
  2180.   while (*str == ' ')
  2181.     str++;
  2182.     
  2183.   if ((conflict_reg = reg_required_here (&str, 12)) == FAIL)
  2184.     {
  2185.       if (!inst.error)
  2186.     inst.error = bad_args;
  2187.       return;
  2188.     }
  2189.  
  2190.   if (skip_past_comma (&str) == FAIL)
  2191.     {
  2192.       inst.error = "Address expected";
  2193.       return;
  2194.     }
  2195.  
  2196.   if (*str == '[')
  2197.     {
  2198.       int reg;
  2199.  
  2200.       str++;
  2201.       while (*str == ' ')
  2202.     str++;
  2203.  
  2204.       if ((reg = reg_required_here (&str, 16)) == FAIL)
  2205.     {
  2206.       inst.error = "Register required";
  2207.       return;
  2208.     }
  2209.  
  2210.       conflict_reg = (((conflict_reg == reg)
  2211.                && (inst.instruction & 0x00100000))
  2212.               ? 1 : 0);
  2213.  
  2214.       while (*str == ' ')
  2215.     str++;
  2216.  
  2217.       if (*str == ']')
  2218.     {
  2219.       str++;
  2220.       if (skip_past_comma (&str) == SUCCESS)
  2221.         {
  2222.           /* [Rn],... (post inc) */
  2223.           if (ldst_extend (&str) == FAIL)
  2224.         return;
  2225.           if (conflict_reg)
  2226.         as_warn ("destination register same as write-back base\n");
  2227.         }
  2228.       else
  2229.         {
  2230.           /* [Rn] */
  2231.           flags |= INDEX_UP;
  2232.           if (! (flags & TRANS_BIT))
  2233.         pre_inc = 1;
  2234.         }
  2235.     }
  2236.       else
  2237.     {
  2238.       /* [Rn,...] */
  2239.       if (skip_past_comma (&str) == FAIL)
  2240.         {
  2241.           inst.error = "pre-indexed expression expected";
  2242.           return;
  2243.         }
  2244.  
  2245.       pre_inc = 1;
  2246.       if (ldst_extend (&str) == FAIL)
  2247.         return;
  2248.  
  2249.       while (*str == ' ')
  2250.         str++;
  2251.  
  2252.       if (*str++ != ']')
  2253.         {
  2254.           inst.error = "missing ]";
  2255.           return;
  2256.         }
  2257.  
  2258.       while (*str == ' ')
  2259.         str++;
  2260.  
  2261.       if (*str == '!')
  2262.         {
  2263.           if (conflict_reg)
  2264.         as_warn ("destination register same as write-back base\n");
  2265.           str++;
  2266.           inst.instruction |= WRITE_BACK;
  2267.         }
  2268.     }
  2269.     }
  2270.   else if (*str == '=')
  2271.     {
  2272.       /* Parse an "ldr Rd, =expr" instruction; this is another pseudo op */
  2273.       str++;
  2274.  
  2275.       while (*str == ' ')
  2276.     str++;
  2277.  
  2278.       if (my_get_expression (&inst.reloc.exp, &str))
  2279.     return;
  2280.  
  2281.       if (inst.reloc.exp.X_op != O_constant
  2282.       && inst.reloc.exp.X_op != O_symbol)
  2283.     {
  2284.       inst.error = "Constant expression expected";
  2285.       return;
  2286.     }
  2287.  
  2288.       if (inst.reloc.exp.X_op == O_constant
  2289.       && (value = validate_immediate(inst.reloc.exp.X_add_number)) != FAIL)
  2290.     {
  2291.       /* This can be done with a mov instruction */
  2292.       inst.instruction &= LITERAL_MASK;
  2293.       inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
  2294.       inst.instruction |= (flags & COND_MASK) | (value & 0xfff);
  2295.       end_of_line(str);
  2296.       return; 
  2297.     }
  2298.       else
  2299.     {
  2300.       /* Insert into literal pool */     
  2301.       if (add_to_lit_pool () == FAIL)
  2302.         {
  2303.           if (!inst.error)
  2304.         inst.error = "literal pool insertion failed\n"; 
  2305.           return;
  2306.         }
  2307.  
  2308.       /* Change the instruction exp to point to the pool */
  2309.       inst.reloc.type = BFD_RELOC_ARM_LITERAL;
  2310.       inst.reloc.pc_rel = 1;
  2311.       inst.instruction |= (REG_PC << 16);
  2312.       pre_inc = 1; 
  2313.     }
  2314.     }
  2315.   else
  2316.     {
  2317.       if (my_get_expression (&inst.reloc.exp, &str))
  2318.     return;
  2319.  
  2320.       inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM;
  2321.       inst.reloc.exp.X_add_number -= 8;  /* PC rel adjust */
  2322.       inst.reloc.pc_rel = 1;
  2323.       inst.instruction |= (REG_PC << 16);
  2324.       pre_inc = 1;
  2325.     }
  2326.     
  2327.   if (pre_inc && (flags & TRANS_BIT))
  2328.     inst.error = "Pre-increment instruction with translate";
  2329.  
  2330.   inst.instruction |= flags | (pre_inc ? PRE_INDEX : 0);
  2331.   end_of_line (str);
  2332.   return;
  2333. }
  2334.  
  2335. static void
  2336. do_ldmstm (str, flags)
  2337.      char *str;
  2338.      unsigned long flags;
  2339. {
  2340.   int base_reg;
  2341.  
  2342.   while (*str == ' ')
  2343.     str++;
  2344.  
  2345.   if ((base_reg = reg_required_here (&str, 16)) == FAIL)
  2346.     {
  2347.       if (!inst.error)
  2348.     inst.error = bad_args;
  2349.       return;
  2350.     }
  2351.  
  2352.   if (base_reg == REG_PC)
  2353.     {
  2354.       inst.error = "r15 not allowed as base register";
  2355.       return;
  2356.     }
  2357.  
  2358.   while (*str == ' ')
  2359.     str++;
  2360.   if (*str == '!')
  2361.     {
  2362.       flags |= WRITE_BACK;
  2363.       str++;
  2364.     }
  2365.  
  2366.   if (skip_past_comma (&str) == FAIL)
  2367.     {
  2368.       inst.error = bad_args;
  2369.       return;
  2370.     }
  2371.  
  2372.   /* We come back here if we get ranges concatenated by '+' or '|' */
  2373.  another_range:
  2374.   if (*str == '{')
  2375.     {
  2376.       int in_range = 0;
  2377.       int cur_reg = -1;
  2378.       
  2379.       str++;
  2380.       do
  2381.     {
  2382.       int reg;
  2383.         
  2384.       while (*str == ' ')
  2385.         str++;
  2386.  
  2387.       if ((reg = arm_reg_parse (&str)) == FAIL || !int_register (reg))
  2388.         {
  2389.           inst.error = "Register expected";
  2390.           return;
  2391.         }
  2392.  
  2393.       if (in_range)
  2394.         {
  2395.           int i;
  2396.           
  2397.           if (reg <= cur_reg)
  2398.         {
  2399.           inst.error = "Bad range in register list";
  2400.           return;
  2401.         }
  2402.  
  2403.           for (i = cur_reg + 1; i < reg; i++)
  2404.         {
  2405.           if (flags & (1 << i))
  2406.             as_tsktsk 
  2407.               ("Warning: Duplicated register (r%d) in register list",
  2408.                i);
  2409.           else
  2410.             flags |= 1 << i;
  2411.         }
  2412.           in_range = 0;
  2413.         }
  2414.  
  2415.       if (flags & (1 << reg))
  2416.         as_tsktsk ("Warning: Duplicated register (r%d) in register list",
  2417.                reg);
  2418.       else if (reg <= cur_reg)
  2419.         as_tsktsk ("Warning: Register range not in ascending order");
  2420.  
  2421.       flags |= 1 << reg;
  2422.       cur_reg = reg;
  2423.     } while (skip_past_comma (&str) != FAIL
  2424.          || (in_range = 1, *str++ == '-'));
  2425.       str--;
  2426.       while (*str == ' ')
  2427.     str++;
  2428.  
  2429.       if (*str++ != '}')
  2430.     {
  2431.       inst.error = "Missing `}'";
  2432.       return;
  2433.     }
  2434.     }
  2435.   else
  2436.     {
  2437.       expressionS expr;
  2438.  
  2439.       if (my_get_expression (&expr, &str))
  2440.     return;
  2441.  
  2442.       if (expr.X_op == O_constant)
  2443.     {
  2444.       if (expr.X_add_number 
  2445.           != (expr.X_add_number & 0x0000ffff))
  2446.         {
  2447.           inst.error = "invalid register mask";
  2448.           return;
  2449.         }
  2450.  
  2451.       if ((flags & expr.X_add_number) != 0)
  2452.         {
  2453.           int regno = flags & expr.X_add_number;
  2454.  
  2455.           regno &= -regno;
  2456.           regno = (1 << regno) - 1;
  2457.           as_tsktsk ("Warning: Duplicated register (r%d) in register list",
  2458.              regno);
  2459.         }
  2460.  
  2461.       flags |= expr.X_add_number;
  2462.     }
  2463.       else
  2464.     {
  2465.       if (inst.reloc.type != 0)
  2466.         {
  2467.           inst.error = "expression too complex";
  2468.           return;
  2469.         }
  2470.  
  2471.       memcpy (&inst.reloc.exp, &expr, sizeof (expressionS));
  2472.       inst.reloc.type = BFD_RELOC_ARM_MULTI;
  2473.       inst.reloc.pc_rel = 0;
  2474.     }
  2475.     }
  2476.  
  2477.   while (*str == ' ')
  2478.     str++;
  2479.  
  2480.   if (*str == '|' || *str == '+')
  2481.     {
  2482.       str++;
  2483.       goto another_range;
  2484.     }
  2485.  
  2486.   if (*str == '^')
  2487.     {
  2488.       str++;
  2489.       flags |= MULTI_SET_PSR;
  2490.     }
  2491.   inst.instruction |= flags;
  2492.   end_of_line (str);
  2493.   return;
  2494. }
  2495.  
  2496. static void
  2497. do_swi (str, flags)
  2498.      char *str;
  2499.      unsigned long flags;
  2500. {
  2501.   /* Allow optional leading '#'.  */
  2502.   while (*str == ' ')
  2503.     str++;
  2504.   if (*str == '#')
  2505.     str++;
  2506.  
  2507.   if (my_get_expression (&inst.reloc.exp, &str))
  2508.     return;
  2509.  
  2510.   inst.reloc.type = BFD_RELOC_ARM_SWI;
  2511.   inst.reloc.pc_rel = 0;
  2512.   inst.instruction |= flags;
  2513.   end_of_line (str);
  2514.   return;
  2515. }
  2516.  
  2517. static void
  2518. do_swap (str, flags)
  2519.      char *str;
  2520.      unsigned long flags;
  2521. {
  2522.   int reg;
  2523.   
  2524.   while (*str == ' ')
  2525.     str++;
  2526.  
  2527.   if ((reg = reg_required_here (&str, 12)) == FAIL)
  2528.     return;
  2529.  
  2530.   if (reg == REG_PC)
  2531.     {
  2532.       inst.error = "r15 not allowed in swap";
  2533.       return;
  2534.     }
  2535.  
  2536.   if (skip_past_comma (&str) == FAIL
  2537.       || (reg = reg_required_here (&str, 0)) == FAIL)
  2538.     {
  2539.       if (!inst.error)
  2540.     inst.error = bad_args;
  2541.       return;
  2542.     }
  2543.  
  2544.   if (reg == REG_PC)
  2545.     {
  2546.       inst.error = "r15 not allowed in swap";
  2547.       return;
  2548.     }
  2549.  
  2550.   if (skip_past_comma (&str) == FAIL
  2551.       || *str++ != '[')
  2552.     {
  2553.       inst.error = bad_args;
  2554.       return;
  2555.     }
  2556.  
  2557.   while (*str == ' ')
  2558.     str++;
  2559.  
  2560.   if ((reg = reg_required_here (&str, 16)) == FAIL)
  2561.     return;
  2562.  
  2563.   if (reg == REG_PC)
  2564.     {
  2565.       inst.error = bad_pc;
  2566.       return;
  2567.     }
  2568.  
  2569.   while (*str == ' ')
  2570.     str++;
  2571.  
  2572.   if (*str++ != ']')
  2573.     {
  2574.       inst.error = "missing ]";
  2575.       return;
  2576.     }
  2577.  
  2578.   inst.instruction |= flags;
  2579.   end_of_line (str);
  2580.   return;
  2581. }
  2582.  
  2583. static void
  2584. do_branch (str, flags)
  2585.      char *str;
  2586.      unsigned long flags;
  2587. {
  2588.   if (my_get_expression (&inst.reloc.exp, &str))
  2589.     return;
  2590.   inst.reloc.type = BFD_RELOC_ARM_PCREL_BRANCH;
  2591.   inst.reloc.pc_rel = 1;
  2592.   inst.instruction |= flags | 0x00fffffe;    /* PC-rel adjust */
  2593.   end_of_line (str);
  2594.   return;
  2595. }
  2596.  
  2597. static void
  2598. do_cdp (str, flags)
  2599.      char *str;
  2600.      unsigned long flags;
  2601. {
  2602.   /* Co-processor data operation.
  2603.      Format: CDP{cond} CP#,<expr>,CRd,CRn,CRm{,<expr>}  */
  2604.   while (*str == ' ')
  2605.     str++;
  2606.  
  2607.   if (co_proc_number (&str) == FAIL)
  2608.     {
  2609.       if (!inst.error)
  2610.     inst.error = bad_args;
  2611.       return;
  2612.     }
  2613.  
  2614.   if (skip_past_comma (&str) == FAIL
  2615.       || cp_opc_expr (&str, 20,4) == FAIL)
  2616.     {
  2617.       if (!inst.error)
  2618.     inst.error = bad_args;
  2619.       return;
  2620.     }
  2621.  
  2622.   if (skip_past_comma (&str) == FAIL
  2623.       || cp_reg_required_here (&str, 12) == FAIL)
  2624.     {
  2625.       if (!inst.error)
  2626.     inst.error = bad_args;
  2627.       return;
  2628.     }
  2629.  
  2630.   if (skip_past_comma (&str) == FAIL
  2631.       || cp_reg_required_here (&str, 16) == FAIL)
  2632.     {
  2633.       if (!inst.error)
  2634.     inst.error = bad_args;
  2635.       return;
  2636.     }
  2637.  
  2638.   if (skip_past_comma (&str) == FAIL
  2639.       || cp_reg_required_here (&str, 0) == FAIL)
  2640.     {
  2641.       if (!inst.error)
  2642.     inst.error = bad_args;
  2643.       return;
  2644.     }
  2645.  
  2646.   if (skip_past_comma (&str) == SUCCESS)
  2647.     {
  2648.       if (cp_opc_expr (&str, 5, 3) == FAIL)
  2649.     {
  2650.       if (!inst.error)
  2651.         inst.error = bad_args;
  2652.       return;
  2653.     }
  2654.     }
  2655.  
  2656.   end_of_line (str);
  2657.   return;
  2658. }
  2659.  
  2660. static void
  2661. do_lstc (str, flags)
  2662.      char *str;
  2663.      unsigned long flags;
  2664. {
  2665.   /* Co-processor register load/store.
  2666.      Format: <LDC|STC{cond}[L] CP#,CRd,<address>  */
  2667.  
  2668.   while (*str == ' ')
  2669.     str++;
  2670.  
  2671.   if (co_proc_number (&str) == FAIL)
  2672.     {
  2673.       if (!inst.error)
  2674.     inst.error = bad_args;
  2675.       return;
  2676.     }
  2677.  
  2678.   if (skip_past_comma (&str) == FAIL
  2679.       || cp_reg_required_here (&str, 12) == FAIL)
  2680.     {
  2681.       if (!inst.error)
  2682.     inst.error = bad_args;
  2683.       return;
  2684.     }
  2685.  
  2686.   if (skip_past_comma (&str) == FAIL
  2687.       || cp_address_required_here (&str) == FAIL)
  2688.     {
  2689.       if (! inst.error)
  2690.     inst.error = bad_args;
  2691.       return;
  2692.     }
  2693.  
  2694.   inst.instruction |= flags;
  2695.   end_of_line (str);
  2696.   return;
  2697. }
  2698.  
  2699. static void
  2700. do_co_reg (str, flags)
  2701.      char *str;
  2702.      unsigned long flags;
  2703. {
  2704.   /* Co-processor register transfer.
  2705.      Format: <MCR|MRC>{cond} CP#,<expr1>,Rd,CRn,CRm{,<expr2>}  */
  2706.  
  2707.   while (*str == ' ')
  2708.     str++;
  2709.  
  2710.   if (co_proc_number (&str) == FAIL)
  2711.     {
  2712.       if (!inst.error)
  2713.     inst.error = bad_args;
  2714.       return;
  2715.     }
  2716.  
  2717.   if (skip_past_comma (&str) == FAIL
  2718.       || cp_opc_expr (&str, 21, 3) == FAIL)
  2719.     {
  2720.       if (!inst.error)
  2721.     inst.error = bad_args;
  2722.       return;
  2723.     }
  2724.  
  2725.   if (skip_past_comma (&str) == FAIL
  2726.       || reg_required_here (&str, 12) == FAIL)
  2727.     {
  2728.       if (!inst.error)
  2729.     inst.error = bad_args;
  2730.       return;
  2731.     }
  2732.  
  2733.   if (skip_past_comma (&str) == FAIL
  2734.       || cp_reg_required_here (&str, 16) == FAIL)
  2735.     {
  2736.       if (!inst.error)
  2737.     inst.error = bad_args;
  2738.       return;
  2739.     }
  2740.  
  2741.   if (skip_past_comma (&str) == FAIL
  2742.       || cp_reg_required_here (&str, 0) == FAIL)
  2743.     {
  2744.       if (!inst.error)
  2745.     inst.error = bad_args;
  2746.       return;
  2747.     }
  2748.  
  2749.   if (skip_past_comma (&str) == SUCCESS)
  2750.     {
  2751.       if (cp_opc_expr (&str, 5, 3) == FAIL)
  2752.     {
  2753.       if (!inst.error)
  2754.         inst.error = bad_args;
  2755.       return;
  2756.     }
  2757.     }
  2758.  
  2759.   end_of_line (str);
  2760.   return;
  2761. }
  2762.  
  2763. static void
  2764. do_fp_ctrl (str, flags)
  2765.      char *str;
  2766.      unsigned long flags;
  2767. {
  2768.   /* FP control registers.
  2769.      Format: <WFS|RFS|WFC|RFC>{cond} Rn  */
  2770.  
  2771.   while (*str == ' ')
  2772.     str++;
  2773.  
  2774.   if (reg_required_here (&str, 12) == FAIL)
  2775.     {
  2776.       if (!inst.error)
  2777.     inst.error = bad_args;
  2778.       return;
  2779.     }
  2780.  
  2781.   end_of_line (str);
  2782.   return;
  2783. }
  2784.  
  2785. static void
  2786. do_fp_ldst (str, flags)
  2787.      char *str;
  2788.      unsigned long flags;
  2789. {
  2790.   while (*str == ' ')
  2791.     str++;
  2792.  
  2793.   switch (inst.suffix)
  2794.     {
  2795.     case SUFF_S:
  2796.       break;
  2797.     case SUFF_D:
  2798.       inst.instruction |= CP_T_X;
  2799.       break;
  2800.     case SUFF_E:
  2801.       inst.instruction |= CP_T_Y;
  2802.       break;
  2803.     case SUFF_P:
  2804.       inst.instruction |= CP_T_X | CP_T_Y;
  2805.       break;
  2806.     default:
  2807.       abort ();
  2808.     }
  2809.  
  2810.   if (fp_reg_required_here (&str, 12) == FAIL)
  2811.     {
  2812.       if (!inst.error)
  2813.     inst.error = bad_args;
  2814.       return;
  2815.     }
  2816.  
  2817.   if (skip_past_comma (&str) == FAIL
  2818.       || cp_address_required_here (&str) == FAIL)
  2819.     {
  2820.       if (!inst.error)
  2821.     inst.error = bad_args;
  2822.       return;
  2823.     }
  2824.  
  2825.   end_of_line (str);
  2826. }
  2827.  
  2828. static void
  2829. do_fp_ldmstm (str, flags)
  2830.      char *str;
  2831.      unsigned long flags;
  2832. {
  2833.   int num_regs;
  2834.  
  2835.   while (*str == ' ')
  2836.     str++;
  2837.  
  2838.   if (fp_reg_required_here (&str, 12) == FAIL)
  2839.     {
  2840.       if (! inst.error)
  2841.     inst.error = bad_args;
  2842.       return;
  2843.     }
  2844.  
  2845.   /* Get Number of registers to transfer */
  2846.   if (skip_past_comma (&str) == FAIL
  2847.       || my_get_expression (&inst.reloc.exp, &str))
  2848.     {
  2849.       if (! inst.error)
  2850.     inst.error = "constant expression expected";
  2851.       return;
  2852.     }
  2853.  
  2854.   if (inst.reloc.exp.X_op != O_constant)
  2855.     {
  2856.       inst.error = "Constant value required for number of registers";
  2857.       return;
  2858.     }
  2859.  
  2860.   num_regs = inst.reloc.exp.X_add_number;
  2861.  
  2862.   if (num_regs < 1 || num_regs > 4)
  2863.     {
  2864.       inst.error = "number of registers must be in the range [1:4]";
  2865.       return;
  2866.     }
  2867.  
  2868.   switch (num_regs)
  2869.     {
  2870.     case 1:
  2871.       inst.instruction |= CP_T_X;
  2872.       break;
  2873.     case 2:
  2874.       inst.instruction |= CP_T_Y;
  2875.       break;
  2876.     case 3:
  2877.       inst.instruction |= CP_T_Y | CP_T_X;
  2878.       break;
  2879.     case 4:
  2880.       break;
  2881.     default:
  2882.       abort ();
  2883.     }
  2884.  
  2885.   if (flags)
  2886.     {
  2887.       int reg;
  2888.       int write_back;
  2889.       int offset;
  2890.  
  2891.       /* The instruction specified "ea" or "fd", so we can only accept
  2892.      [Rn]{!}.  The instruction does not really support stacking or
  2893.      unstacking, so we have to emulate these by setting appropriate
  2894.      bits and offsets.  */
  2895.       if (skip_past_comma (&str) == FAIL
  2896.       || *str != '[')
  2897.     {
  2898.       if (! inst.error)
  2899.         inst.error = bad_args;
  2900.       return;
  2901.     }
  2902.  
  2903.       str++;
  2904.       while (*str == ' ')
  2905.     str++;
  2906.  
  2907.       if ((reg = reg_required_here (&str, 16)) == FAIL)
  2908.     {
  2909.       inst.error = "Register required";
  2910.       return;
  2911.     }
  2912.  
  2913.       while (*str == ' ')
  2914.     str++;
  2915.  
  2916.       if (*str != ']')
  2917.     {
  2918.       inst.error = bad_args;
  2919.       return;
  2920.     }
  2921.  
  2922.       str++;
  2923.       if (*str == '!')
  2924.     {
  2925.       write_back = 1;
  2926.       str++;
  2927.       if (reg == REG_PC)
  2928.         {
  2929.           inst.error = "R15 not allowed as base register with write-back";
  2930.           return;
  2931.         }
  2932.     }
  2933.       else
  2934.     write_back = 0;
  2935.  
  2936.       if (flags & CP_T_Pre)
  2937.     {
  2938.       /* Pre-decrement */
  2939.       offset = 3 * num_regs;
  2940.       if (write_back)
  2941.         flags |= CP_T_WB;
  2942.     }
  2943.       else
  2944.     {
  2945.       /* Post-increment */
  2946.       if (write_back)
  2947.         {
  2948.           flags |= CP_T_WB;
  2949.           offset = 3 * num_regs;
  2950.         }
  2951.       else
  2952.         {
  2953.           /* No write-back, so convert this into a standard pre-increment
  2954.          instruction -- aesthetically more pleasing.  */
  2955.           flags = CP_T_Pre | CP_T_UD;
  2956.           offset = 0;
  2957.         }
  2958.     }
  2959.  
  2960.       inst.instruction |= flags | offset;
  2961.     }
  2962.   else if (skip_past_comma (&str) == FAIL
  2963.        || cp_address_required_here (&str) == FAIL)
  2964.     {
  2965.       if (! inst.error)
  2966.     inst.error = bad_args;
  2967.       return;
  2968.     }
  2969.  
  2970.   end_of_line (str);
  2971. }
  2972.  
  2973. static void
  2974. do_fp_dyadic (str, flags)
  2975.      char *str;
  2976.      unsigned long flags;
  2977. {
  2978.   while (*str == ' ')
  2979.     str++;
  2980.  
  2981.   switch (inst.suffix)
  2982.     {
  2983.     case SUFF_S:
  2984.       break;
  2985.     case SUFF_D:
  2986.       inst.instruction |= 0x00000080;
  2987.       break;
  2988.     case SUFF_E:
  2989.       inst.instruction |= 0x00080000;
  2990.       break;
  2991.     default:
  2992.       abort ();
  2993.     }
  2994.  
  2995.   if (fp_reg_required_here (&str, 12) == FAIL)
  2996.     {
  2997.       if (! inst.error)
  2998.     inst.error = bad_args;
  2999.       return;
  3000.     }
  3001.  
  3002.   if (skip_past_comma (&str) == FAIL
  3003.       || fp_reg_required_here (&str, 16) == FAIL)
  3004.     {
  3005.       if (! inst.error)
  3006.     inst.error = bad_args;
  3007.       return;
  3008.     }
  3009.  
  3010.   if (skip_past_comma (&str) == FAIL
  3011.       || fp_op2 (&str) == FAIL)
  3012.     {
  3013.       if (! inst.error)
  3014.     inst.error = bad_args;
  3015.       return;
  3016.     }
  3017.  
  3018.   inst.instruction |= flags;
  3019.   end_of_line (str);
  3020.   return;
  3021. }
  3022.  
  3023. static void
  3024. do_fp_monadic (str, flags)
  3025.      char *str;
  3026.      unsigned long flags;
  3027. {
  3028.   while (*str == ' ')
  3029.     str++;
  3030.  
  3031.   switch (inst.suffix)
  3032.     {
  3033.     case SUFF_S:
  3034.       break;
  3035.     case SUFF_D:
  3036.       inst.instruction |= 0x00000080;
  3037.       break;
  3038.     case SUFF_E:
  3039.       inst.instruction |= 0x00080000;
  3040.       break;
  3041.     default:
  3042.       abort ();
  3043.     }
  3044.  
  3045.   if (fp_reg_required_here (&str, 12) == FAIL)
  3046.     {
  3047.       if (! inst.error)
  3048.     inst.error = bad_args;
  3049.       return;
  3050.     }
  3051.  
  3052.   if (skip_past_comma (&str) == FAIL
  3053.       || fp_op2 (&str) == FAIL)
  3054.     {
  3055.       if (! inst.error)
  3056.     inst.error = bad_args;
  3057.       return;
  3058.     }
  3059.  
  3060.   inst.instruction |= flags;
  3061.   end_of_line (str);
  3062.   return;
  3063. }
  3064.  
  3065. static void
  3066. do_fp_cmp (str, flags)
  3067.      char *str;
  3068.      unsigned long flags;
  3069. {
  3070.   while (*str == ' ')
  3071.     str++;
  3072.  
  3073.   if (fp_reg_required_here (&str, 16) == FAIL)
  3074.     {
  3075.       if (! inst.error)
  3076.     inst.error = bad_args;
  3077.       return;
  3078.     }
  3079.  
  3080.   if (skip_past_comma (&str) == FAIL
  3081.       || fp_op2 (&str) == FAIL)
  3082.     {
  3083.       if (! inst.error)
  3084.     inst.error = bad_args;
  3085.       return;
  3086.     }
  3087.  
  3088.   inst.instruction |= flags;
  3089.   end_of_line (str);
  3090.   return;
  3091. }
  3092.  
  3093. static void
  3094. do_fp_from_reg (str, flags)
  3095.      char *str;
  3096.      unsigned long flags;
  3097. {
  3098.   while (*str == ' ')
  3099.     str++;
  3100.  
  3101.   switch (inst.suffix)
  3102.     {
  3103.     case SUFF_S:
  3104.       break;
  3105.     case SUFF_D:
  3106.       inst.instruction |= 0x00000080;
  3107.       break;
  3108.     case SUFF_E:
  3109.       inst.instruction |= 0x00080000;
  3110.       break;
  3111.     default:
  3112.       abort ();
  3113.     }
  3114.  
  3115.   if (fp_reg_required_here (&str, 16) == FAIL)
  3116.     {
  3117.       if (! inst.error)
  3118.     inst.error = bad_args;
  3119.       return;
  3120.     }
  3121.  
  3122.   if (skip_past_comma (&str) == FAIL
  3123.       || reg_required_here (&str, 12) == FAIL)
  3124.     {
  3125.       if (! inst.error)
  3126.     inst.error = bad_args;
  3127.       return;
  3128.     }
  3129.  
  3130.   inst.instruction |= flags;
  3131.   end_of_line (str);
  3132.   return;
  3133. }
  3134.  
  3135. static void
  3136. do_fp_to_reg (str, flags)
  3137.      char *str;
  3138.      unsigned long flags;
  3139. {
  3140.   while (*str == ' ')
  3141.     str++;
  3142.  
  3143.   if (reg_required_here (&str, 12) == FAIL)
  3144.     {
  3145.       if (! inst.error)
  3146.     inst.error = bad_args;
  3147.       return;
  3148.     }
  3149.  
  3150.   if (skip_past_comma (&str) == FAIL
  3151.       || fp_reg_required_here (&str, 0) == FAIL)
  3152.     {
  3153.       if (! inst.error)
  3154.     inst.error = bad_args;
  3155.       return;
  3156.     }
  3157.  
  3158.   inst.instruction |= flags;
  3159.   end_of_line (str);
  3160.   return;
  3161. }
  3162.  
  3163. static void
  3164. insert_reg (entry)
  3165.      int entry;
  3166. {
  3167.   int len = strlen (reg_table[entry].name) + 2;
  3168.   char *buf = (char *) xmalloc (len);
  3169.   char *buf2 = (char *) xmalloc (len);
  3170.   int i = 0;
  3171.  
  3172. #ifdef REGISTER_PREFIX
  3173.   buf[i++] = REGISTER_PREFIX;
  3174. #endif
  3175.  
  3176.   strcpy (buf + i, reg_table[entry].name);
  3177.  
  3178.   for (i = 0; buf[i]; i++)
  3179.     buf2[i] = islower (buf[i]) ? toupper (buf[i]) : buf[i];
  3180.  
  3181.   buf2[i] = '\0';
  3182.  
  3183.   hash_insert (arm_reg_hsh, buf, (PTR) ®_table[entry]);
  3184.   hash_insert (arm_reg_hsh, buf2, (PTR) ®_table[entry]);
  3185. }
  3186.  
  3187. static void
  3188. insert_reg_alias (str, regnum)
  3189.      char *str;
  3190.      int regnum;
  3191. {
  3192.   struct reg_entry *new =
  3193.     (struct reg_entry *)xmalloc (sizeof (struct reg_entry));
  3194.   char *name = xmalloc (strlen (str) + 1);
  3195.   strcpy (name, str);
  3196.  
  3197.   new->name = name;
  3198.   new->number = regnum;
  3199.  
  3200.   hash_insert (arm_reg_hsh, name, (PTR) new);
  3201. }
  3202.  
  3203. static void
  3204. set_constant_flonums ()
  3205. {
  3206.   int i;
  3207.  
  3208.   for (i = 0; i < NUM_FLOAT_VALS; i++)
  3209.     if (atof_ieee ((char *)fp_const[i], 'x', fp_values[i]) == NULL)
  3210.       abort ();
  3211. }
  3212.  
  3213. void
  3214. md_begin ()
  3215. {
  3216.   int i;
  3217.  
  3218.   if ((arm_ops_hsh = hash_new ()) == NULL
  3219.       || (arm_cond_hsh = hash_new ()) == NULL
  3220.       || (arm_shift_hsh = hash_new ()) == NULL
  3221.       || (arm_reg_hsh = hash_new ()) == NULL
  3222.       || (arm_psr_hsh = hash_new ()) == NULL)
  3223.     as_fatal ("Virtual memory exhausted");
  3224.     
  3225.   for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
  3226.     hash_insert (arm_ops_hsh, insns[i].template, (PTR) (insns + i));
  3227.   for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
  3228.     hash_insert (arm_cond_hsh, conds[i].template, (PTR) (conds + i));
  3229.   for (i = 0; i < sizeof (shift) / sizeof (struct asm_shift); i++)
  3230.     hash_insert (arm_shift_hsh, shift[i].template, (PTR) (shift + i));
  3231.   for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
  3232.     hash_insert (arm_psr_hsh, psrs[i].template, (PTR) (psrs + i));
  3233.  
  3234.   for (i = 0; reg_table[i].name; i++)
  3235.     insert_reg (i);
  3236.  
  3237.   set_constant_flonums ();
  3238. }
  3239.  
  3240. /* Turn an integer of n bytes (in val) into a stream of bytes appropriate
  3241.    for use in the a.out file, and stores them in the array pointed to by buf.
  3242.    This knows about the endian-ness of the target machine and does
  3243.    THE RIGHT THING, whatever it is.  Possible values for n are 1 (byte)
  3244.    2 (short) and 4 (long)  Floating numbers are put out as a series of
  3245.    LITTLENUMS (shorts, here at least)
  3246.    */
  3247. void
  3248. md_number_to_chars (buf, val, n)
  3249.      char *buf;
  3250.      valueT val;
  3251.      int n;
  3252. {
  3253.   if (target_big_endian)
  3254.     number_to_chars_bigendian (buf, val, n);
  3255.   else
  3256.     number_to_chars_littleendian (buf, val, n);
  3257. }
  3258.  
  3259. static valueT 
  3260. md_chars_to_number (buf, n)
  3261.      char *buf;
  3262.      int n;
  3263. {
  3264.   valueT result = 0;
  3265.   unsigned char *where = (unsigned char *) buf;
  3266.  
  3267.   if (target_big_endian)
  3268.     {
  3269.       while (n--)
  3270.     {
  3271.       result <<= 8;
  3272.       result |= (*where++ & 255);
  3273.     }
  3274.     }
  3275.   else
  3276.     {
  3277.       while (n--)
  3278.     {
  3279.       result <<= 8;
  3280.       result |= (where[n] & 255);
  3281.     }
  3282.     }
  3283.  
  3284.   return result;
  3285. }
  3286.  
  3287. /* Turn a string in input_line_pointer into a floating point constant
  3288.    of type TYPE, and store the appropriate bytes in *litP.  The number
  3289.    of LITTLENUMS emitted is stored in *sizeP .  An error message is
  3290.    returned, or NULL on OK.
  3291.  
  3292.    Note that fp constants aren't represent in the normal way on the ARM.
  3293.    In big endian mode, things are as expected.  However, in little endian
  3294.    mode fp constants are big-endian word-wise, and little-endian byte-wise
  3295.    within the words.  For example, (double) 1.1 in big endian mode is
  3296.    the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
  3297.    the byte sequence 99 99 f1 3f 9a 99 99 99.
  3298.  
  3299.    ??? The format of 12 byte floats is uncertain according to gcc's arm.h.  */
  3300.  
  3301. char *
  3302. md_atof (type, litP, sizeP)
  3303.      char type;
  3304.      char *litP;
  3305.      int *sizeP;
  3306. {
  3307.   int prec;
  3308.   LITTLENUM_TYPE words[MAX_LITTLENUMS];
  3309.   char *t;
  3310.   int i;
  3311.  
  3312.   switch (type)
  3313.     {
  3314.     case 'f':
  3315.     case 'F':
  3316.     case 's':
  3317.     case 'S':
  3318.       prec = 2;
  3319.       break;
  3320.  
  3321.     case 'd':
  3322.     case 'D':
  3323.     case 'r':
  3324.     case 'R':
  3325.       prec = 4;
  3326.       break;
  3327.  
  3328.     case 'x':
  3329.     case 'X':
  3330.       prec = 6;
  3331.       break;
  3332.  
  3333.     case 'p':
  3334.     case 'P':
  3335.       prec = 6;
  3336.       break;
  3337.  
  3338.     default:
  3339.       *sizeP = 0;
  3340.       return "Bad call to MD_ATOF()";
  3341.     }
  3342.  
  3343.   t = atof_ieee (input_line_pointer, type, words);
  3344.   if (t)
  3345.     input_line_pointer = t;
  3346.   *sizeP = prec * 2;
  3347.  
  3348.   if (target_big_endian)
  3349.     {
  3350.       for (i = 0; i < prec; i++)
  3351.     {
  3352.       md_number_to_chars (litP, (valueT) words[i], 2);
  3353.       litP += 2;
  3354.     }
  3355.     }
  3356.   else
  3357.     {
  3358.       /* For a 4 byte float the order of elements in `words' is 1 0.  For an
  3359.      8 byte float the order is 1 0 3 2.  */
  3360.       for (i = 0; i < prec; i += 2)
  3361.     {
  3362.       md_number_to_chars (litP, (valueT) words[i + 1], 2);
  3363.       md_number_to_chars (litP + 2, (valueT) words[i], 2);
  3364.       litP += 4;
  3365.     }
  3366.     }
  3367.  
  3368.   return 0;
  3369. }
  3370.  
  3371. /* We have already put the pipeline compensation in the instruction */
  3372.  
  3373. long
  3374. md_pcrel_from (fixP)
  3375.      fixS *fixP;
  3376. {
  3377.   if (fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) == undefined_section
  3378.       && fixP->fx_subsy == NULL)
  3379.     return 0;    /* HACK */
  3380.  
  3381.   return fixP->fx_where + fixP->fx_frag->fr_address;
  3382. }
  3383.  
  3384. /* Round up a section size to the appropriate boundary. */
  3385. valueT
  3386. md_section_align (segment, size)
  3387.      segT segment;
  3388.      valueT size;
  3389. {
  3390.   /* Round all sects to multiple of 4 */
  3391.   return (size + 3) & ~3;
  3392. }
  3393.  
  3394. /* We have no need to default values of symbols.  */
  3395.  
  3396. /* ARGSUSED */
  3397. symbolS *
  3398. md_undefined_symbol (name)
  3399.      char *name;
  3400. {
  3401.   return 0;
  3402. }
  3403.  
  3404. /* arm_reg_parse () := if it looks like a register, return its token and 
  3405.    advance the pointer. */
  3406.  
  3407. static int
  3408. arm_reg_parse (ccp)
  3409.      register char **ccp;
  3410. {
  3411.   char *start = *ccp;
  3412.   char c;
  3413.   char *p;
  3414.   struct reg_entry *reg;
  3415.  
  3416. #ifdef REGISTER_PREFIX
  3417.   if (*start != REGISTER_PREFIX)
  3418.     return FAIL;
  3419.   p = start + 1;
  3420. #else
  3421.   p = start;
  3422. #ifdef OPTIONAL_REGISTER_PREFIX
  3423.   if (*p == OPTIONAL_REGISTER_PREFIX)
  3424.     p++, start++;
  3425. #endif
  3426. #endif
  3427.   if (!isalpha (*p) || !is_name_beginner (*p))
  3428.     return FAIL;
  3429.  
  3430.   c = *p++;
  3431.   while (isalpha (c) || isdigit (c) || c == '_')
  3432.     c = *p++;
  3433.  
  3434.   *--p = 0;
  3435.   reg = (struct reg_entry *) hash_find (arm_reg_hsh, start);
  3436.   *p = c;
  3437.   
  3438.   if (reg)
  3439.     {
  3440.       *ccp = p;
  3441.       return reg->number;
  3442.     }
  3443.  
  3444.   return FAIL;
  3445. }
  3446.  
  3447. static int
  3448. arm_psr_parse (ccp)
  3449.      register char **ccp;
  3450. {
  3451.   char *start = *ccp;
  3452.   char c, *p;
  3453.   CONST struct asm_psr *psr;
  3454.  
  3455.   p = start;
  3456.   c = *p++;
  3457.   while (isalpha (c) || c == '_')
  3458.     c = *p++;
  3459.  
  3460.   *--p = 0;  
  3461.   psr = (CONST struct asm_psr *) hash_find (arm_psr_hsh, start);
  3462.   *p = c;
  3463.  
  3464.   if (psr)
  3465.     {
  3466.       *ccp = p;
  3467.       return psr->number;
  3468.     }
  3469.  
  3470.   return FAIL;
  3471. }
  3472.  
  3473. int
  3474. md_apply_fix3 (fixP, val, seg)
  3475.      fixS *fixP;
  3476.      valueT *val;
  3477.      segT seg;
  3478. {
  3479.   offsetT value = *val;
  3480.   offsetT newval, temp;
  3481.   int sign;
  3482.   char *buf = fixP->fx_where + fixP->fx_frag->fr_literal;
  3483.  
  3484.   assert (fixP->fx_r_type < BFD_RELOC_UNUSED);
  3485.  
  3486.   /* Note whether this will delete the relocation.  */
  3487.   if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
  3488.     fixP->fx_done = 1;
  3489.  
  3490.   /* If this symbol is in a different section then we need to leave it for
  3491.      the linker to deal with.  Unfortunately, md_pcrel_from can't tell,
  3492.      so we have to undo it's effects here.  */
  3493.   if (fixP->fx_pcrel)
  3494.     {
  3495.       if (S_IS_DEFINED (fixP->fx_addsy)
  3496.       && S_GET_SEGMENT (fixP->fx_addsy) != seg)
  3497.     value += md_pcrel_from (fixP);
  3498.     }
  3499.  
  3500.   fixP->fx_addnumber = value;    /* Remember value for emit_reloc */
  3501.  
  3502.   switch (fixP->fx_r_type)
  3503.     {
  3504.     case BFD_RELOC_ARM_IMMEDIATE:
  3505.       newval = validate_immediate (value);
  3506.       temp = md_chars_to_number (buf, INSN_SIZE);
  3507.  
  3508.       /* If the instruction will fail, see if we can fix things up by
  3509.      changing the opcode.  */
  3510.       if (newval == FAIL
  3511.       && (newval = negate_data_op (&temp, value)) == FAIL)
  3512.     {
  3513.       as_bad_where (fixP->fx_file, fixP->fx_line,
  3514.             "invalid constant after fixup\n");
  3515.       break;
  3516.     }
  3517.  
  3518.       newval |= (temp & 0xfffff000);
  3519.       md_number_to_chars (buf, newval, INSN_SIZE);
  3520.       break;
  3521.  
  3522.     case BFD_RELOC_ARM_OFFSET_IMM:
  3523.       sign = value >= 0;
  3524.       value = validate_offset_imm (value); /* Should be OK ... but .... */
  3525.       if (value < 0)
  3526.     value = -value;
  3527.  
  3528.       newval = md_chars_to_number (buf, INSN_SIZE);
  3529.       newval &= 0xff7ff000;
  3530.       newval |= value | (sign ? 0x00800000 : 0);
  3531.       md_number_to_chars (buf, newval, INSN_SIZE);
  3532.       break;
  3533.  
  3534.     case BFD_RELOC_ARM_LITERAL:
  3535.       sign = value >= 0;
  3536.       if (value < 0)
  3537.     value = -value;
  3538.  
  3539.       if ((value = validate_immediate (value)) == FAIL)
  3540.     {
  3541.       as_bad_where (fixP->fx_file, fixP->fx_line, 
  3542.             "invalid literal constant: pool needs to be closer\n");
  3543.       break;
  3544.     }
  3545.  
  3546.       newval = md_chars_to_number (buf, INSN_SIZE);
  3547.       newval &= 0xff7ff000;
  3548.       newval |= value | (sign ? 0x00800000 : 0);
  3549.       md_number_to_chars (buf, newval, INSN_SIZE);
  3550.       break;
  3551.  
  3552.     case BFD_RELOC_ARM_SHIFT_IMM:
  3553.       newval = md_chars_to_number (buf, INSN_SIZE);
  3554.       if (((unsigned long) value) > 32
  3555.       || (value == 32 
  3556.           && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
  3557.     {
  3558.       as_bad_where (fixP->fx_file, fixP->fx_line,
  3559.             "shift expression is too large");
  3560.       break;
  3561.     }
  3562.  
  3563.       if (value == 0)
  3564.     newval &= ~0x60;    /* Shifts of zero must be done as lsl */
  3565.       else if (value == 32)
  3566.     value = 0;
  3567.       newval &= 0xfffff07f;
  3568.       newval |= (value & 0x1f) << 7;
  3569.       md_number_to_chars (buf, newval , INSN_SIZE);
  3570.       break;
  3571.  
  3572.     case BFD_RELOC_ARM_SWI:
  3573.       if (((unsigned long) value) > 0x00ffffff)
  3574.     as_bad_where (fixP->fx_file, fixP->fx_line, "Invalid swi expression");
  3575.       newval = md_chars_to_number (buf, INSN_SIZE) & 0xff000000;
  3576.       newval |= value;
  3577.       md_number_to_chars (buf, newval , INSN_SIZE);
  3578.       break;
  3579.  
  3580.     case BFD_RELOC_ARM_MULTI:
  3581.       if (((unsigned long) value) > 0xffff)
  3582.     as_bad_where (fixP->fx_file, fixP->fx_line,
  3583.               "Invalid expression in load/store multiple");
  3584.       newval = value | md_chars_to_number (buf, INSN_SIZE);
  3585.       md_number_to_chars (buf, newval, INSN_SIZE);
  3586.       break;
  3587.  
  3588.     case BFD_RELOC_ARM_PCREL_BRANCH:
  3589.       value = (value >> 2) & 0x00ffffff;
  3590.       newval = md_chars_to_number (buf, INSN_SIZE);
  3591.       value = (value + (newval & 0x00ffffff)) & 0x00ffffff;
  3592.       newval = value | (newval & 0xff000000);
  3593.       md_number_to_chars (buf, newval, INSN_SIZE);
  3594.       break;
  3595.  
  3596.     case BFD_RELOC_8:
  3597.       if (fixP->fx_done || fixP->fx_pcrel)
  3598.     md_number_to_chars (buf, value, 1);
  3599.       break;
  3600.  
  3601.     case BFD_RELOC_16:
  3602.       if (fixP->fx_done || fixP->fx_pcrel)
  3603.     md_number_to_chars (buf, value, 2);
  3604.       break;
  3605.  
  3606.     case BFD_RELOC_RVA:
  3607.     case BFD_RELOC_32:
  3608.       if (fixP->fx_done || fixP->fx_pcrel)
  3609.     md_number_to_chars (buf, value, 4);
  3610.       break;
  3611.  
  3612.     case BFD_RELOC_ARM_CP_OFF_IMM:
  3613.       sign = value >= 0;
  3614.       if (value < -1023 || value > 1023 || (value & 3))
  3615.     as_bad_where (fixP->fx_file, fixP->fx_line,
  3616.               "Illegal value for co-processor offset");
  3617.       if (value < 0)
  3618.     value = -value;
  3619.       newval = md_chars_to_number (buf, INSN_SIZE) & 0xff7fff00;
  3620.       newval |= (value >> 2) | (sign ?  0x00800000 : 0);
  3621.       md_number_to_chars (buf, newval , INSN_SIZE);
  3622.       break;
  3623.  
  3624.     case BFD_RELOC_NONE:
  3625.     default:
  3626.       as_bad_where (fixP->fx_file, fixP->fx_line,
  3627.             "Bad relocation fixup type (%d)\n", fixP->fx_r_type);
  3628.     }
  3629.  
  3630.   return 1;
  3631. }
  3632.  
  3633. /* Translate internal representation of relocation info to BFD target
  3634.    format.  */
  3635. arelent *
  3636. tc_gen_reloc (section, fixp)
  3637.      asection *section;
  3638.      fixS *fixp;
  3639. {
  3640.   arelent *reloc;
  3641.   bfd_reloc_code_real_type code;
  3642.  
  3643.   reloc = (arelent *) bfd_alloc_by_size_t (stdoutput, sizeof (arelent));
  3644.   assert (reloc != 0);
  3645.  
  3646.   reloc->sym_ptr_ptr = &fixp->fx_addsy->bsym;
  3647.   reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
  3648.  
  3649.   /* @@ Why fx_addnumber sometimes and fx_offset other times?  */
  3650.   if (fixp->fx_pcrel == 0)
  3651.     reloc->addend = fixp->fx_offset;
  3652.   else
  3653.     reloc->addend = fixp->fx_offset = reloc->address;
  3654.  
  3655.   switch (fixp->fx_r_type)
  3656.     {
  3657.     case BFD_RELOC_8:
  3658.       if (fixp->fx_pcrel)
  3659.     {
  3660.       code = BFD_RELOC_8_PCREL;
  3661.       break;
  3662.     }
  3663.  
  3664.     case BFD_RELOC_16:
  3665.       if (fixp->fx_pcrel)
  3666.     {
  3667.       code = BFD_RELOC_16_PCREL;
  3668.       break;
  3669.     }
  3670.  
  3671.     case BFD_RELOC_32:
  3672.       if (fixp->fx_pcrel)
  3673.     {
  3674.       code = BFD_RELOC_32_PCREL;
  3675.       break;
  3676.     }
  3677.  
  3678.     case BFD_RELOC_ARM_PCREL_BRANCH:
  3679.     case BFD_RELOC_RVA:      
  3680.       code = fixp->fx_r_type;
  3681.       break;
  3682.  
  3683.     case BFD_RELOC_ARM_LITERAL:
  3684.       /* If this is called then the a literal has been referenced across
  3685.      a section boundry - possibly due to an implicit dump */
  3686.       as_bad ("Literal referenced across section boundry (Implicit dump?)");
  3687.       return NULL;
  3688.  
  3689.     case BFD_RELOC_ARM_IMMEDIATE:
  3690.       as_bad ("Internal_relocation (type %d) not fixed up (IMMEDIATE)"
  3691.           , fixp->fx_r_type);
  3692.       return NULL;
  3693.  
  3694.     case BFD_RELOC_ARM_OFFSET_IMM:
  3695.       as_bad ("Internal_relocation (type %d) not fixed up (OFFSET_IMM)"
  3696.           , fixp->fx_r_type);
  3697.       return NULL;
  3698.  
  3699.     case BFD_RELOC_ARM_SHIFT_IMM:
  3700.       as_bad ("Internal_relocation (type %d) not fixed up (SHIFT_IMM)"
  3701.           , fixp->fx_r_type);
  3702.       return NULL;
  3703.  
  3704.     case BFD_RELOC_ARM_SWI:
  3705.       as_bad ("Internal_relocation (type %d) not fixed up (SWI)"
  3706.           , fixp->fx_r_type);
  3707.       return NULL;
  3708.  
  3709.     case BFD_RELOC_ARM_MULTI:
  3710.       as_bad ("Internal_relocation (type %d) not fixed up (MULTI)"
  3711.           , fixp->fx_r_type);
  3712.       return NULL;
  3713.  
  3714.     case BFD_RELOC_ARM_CP_OFF_IMM:
  3715.       as_bad ("Internal_relocation (type %d) not fixed up (CP_OFF_IMM)"
  3716.           , fixp->fx_r_type);
  3717.       return NULL;
  3718.  
  3719.     default:
  3720.       abort ();
  3721.     }
  3722.  
  3723.   reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
  3724.   assert (reloc->howto != 0);
  3725.  
  3726.   return reloc;
  3727. }
  3728.  
  3729. CONST int md_short_jump_size = 4;
  3730. CONST int md_long_jump_size = 4;
  3731.  
  3732. /* These should never be called on the arm */
  3733. void
  3734. md_create_long_jump (ptr, from_addr, to_addr, frag, to_symbol)
  3735.      char *ptr;
  3736.      addressT from_addr, to_addr;
  3737.      fragS *frag;
  3738.      symbolS *to_symbol;
  3739. {
  3740.   as_fatal ("md_create_long_jump\n");
  3741. }
  3742.  
  3743. void
  3744. md_create_short_jump (ptr, from_addr, to_addr, frag, to_symbol)
  3745.      char *ptr;
  3746.      addressT from_addr, to_addr;
  3747.      fragS *frag;
  3748.      symbolS *to_symbol;
  3749. {
  3750.   as_fatal ("md_create_short_jump\n");
  3751. }
  3752.  
  3753. int
  3754. md_estimate_size_before_relax (fragP, segtype)
  3755.      fragS *fragP;
  3756.      segT segtype;
  3757. {
  3758.   as_fatal ("md_estimate_size_before_relax\n");
  3759.   return (1);
  3760. }
  3761.  
  3762. void
  3763. output_inst (str)
  3764.      char *str;
  3765. {
  3766.   char *to = NULL;
  3767.     
  3768.   if (inst.error)
  3769.     {
  3770.       as_bad ("%s -- statement `%s'\n", inst.error, str);
  3771.       return;
  3772.     }
  3773.  
  3774.   to = frag_more (INSN_SIZE);
  3775.   md_number_to_chars (to, inst.instruction, INSN_SIZE);
  3776.  
  3777.   if (inst.reloc.type != BFD_RELOC_NONE)
  3778.     fix_new_arm (frag_now, to - frag_now->fr_literal,
  3779.          4, &inst.reloc.exp, inst.reloc.pc_rel,
  3780.          inst.reloc.type);
  3781.  
  3782.   return;
  3783. }
  3784.  
  3785. void
  3786. md_assemble (str)
  3787.      char *str;
  3788. {
  3789.   char c;
  3790.   CONST struct asm_opcode *opcode;
  3791.   char *p, *q, *start;
  3792.  
  3793.   /* Align the instruction */
  3794.   /* this may not be the right thing to do but ... */
  3795.   /* arm_align (2, 0); */
  3796.   listing_prev_line (); /* Defined in listing.h */
  3797.  
  3798.   /* Align the previous label if needed */
  3799.   if (last_label_seen != NULL)
  3800.     {
  3801.       last_label_seen->sy_frag = frag_now;
  3802.       S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
  3803.       S_SET_SEGMENT (last_label_seen, now_seg);
  3804.     }
  3805.  
  3806.   memset (&inst, '\0', sizeof (inst));
  3807.   inst.reloc.type = BFD_RELOC_NONE;
  3808.  
  3809.   if (*str == ' ')
  3810.     str++;            /* Skip leading white space */
  3811.     
  3812.   /* scan up to the end of the op-code, which must end in white space or
  3813.      end of string */
  3814.   for (start = p = str; *p != '\0'; p++)
  3815.     if (*p == ' ')
  3816.       break;
  3817.     
  3818.   if (p == str)
  3819.     {
  3820.       as_bad ("No operator -- statement `%s'\n", str);
  3821.       return;
  3822.     }
  3823.  
  3824.   /* p now points to the end of the opcode, probably white space, but we have
  3825.      to break the opcode up in case it contains condionals and flags;
  3826.      keep trying with progressively smaller basic instructions until one
  3827.      matches, or we run out of opcode. */
  3828.   q = (p - str > LONGEST_INST) ? str + LONGEST_INST : p;
  3829.   for (; q != str; q--)
  3830.     {
  3831.       c = *q;
  3832.       *q = '\0';
  3833.       opcode = (CONST struct asm_opcode *) hash_find (arm_ops_hsh, str);
  3834.       *q = c;
  3835.       if (opcode && opcode->template)
  3836.     {
  3837.       unsigned long flag_bits = 0;
  3838.       char *r;
  3839.  
  3840.       /* Check that this instruction is supported for this CPU */
  3841.       if ((opcode->variants & cpu_variant) == 0)
  3842.         goto try_shorter;
  3843.  
  3844.       inst.instruction = opcode->value;
  3845.       if (q == p)        /* Just a simple opcode */
  3846.         {
  3847.           if (opcode->comp_suffix != 0)
  3848.         as_bad ("Opcode `%s' must have suffix from <%s>\n", str,
  3849.             opcode->comp_suffix);
  3850.           else
  3851.         {
  3852.           inst.instruction |= COND_ALWAYS;
  3853.           (*opcode->parms)(q, 0);
  3854.         }
  3855.           output_inst (start);
  3856.           return;
  3857.         }
  3858.  
  3859.       /* Now check for a conditional */
  3860.       r = q;
  3861.       if (p - r >= 2)
  3862.         {
  3863.           CONST struct asm_cond *cond;
  3864.           char d = *(r + 2);
  3865.           
  3866.           *(r + 2) = '\0';
  3867.           cond = (CONST struct asm_cond *) hash_find (arm_cond_hsh, r);
  3868.           *(r + 2) = d;
  3869.           if (cond)
  3870.         {
  3871.           if (cond->value == 0xf0000000)
  3872.             as_tsktsk
  3873.               ("Warning: Use of the 'nv' conditional is deprecated\n");
  3874.  
  3875.           inst.instruction |= cond->value;
  3876.           r += 2;
  3877.         }
  3878.           else
  3879.         inst.instruction |= COND_ALWAYS;
  3880.         }
  3881.       else
  3882.         inst.instruction |= COND_ALWAYS;
  3883.  
  3884.       /* if there is a compulsory suffix, it should come here, before
  3885.          any optional flags. */
  3886.       if (opcode->comp_suffix)
  3887.         {
  3888.           CONST char *s = opcode->comp_suffix;
  3889.  
  3890.           while (*s)
  3891.         {
  3892.           inst.suffix++;
  3893.           if (*r == *s)
  3894.             break;
  3895.           s++;
  3896.         }
  3897.           
  3898.           if (*s == '\0')
  3899.         {
  3900.           as_bad ("Opcode `%s' must have suffix from <%s>\n", str,
  3901.               opcode->comp_suffix);
  3902.           return;
  3903.         }
  3904.         
  3905.           r++;
  3906.         }
  3907.  
  3908.       /* The remainder, if any should now be flags for the instruction;
  3909.          Scan these checking each one found with the opcode.  */
  3910.       if (r != p)
  3911.         {
  3912.           char d;
  3913.           CONST struct asm_flg *flag = opcode->flags;
  3914.  
  3915.           if (flag)
  3916.         {
  3917.           int flagno;
  3918.  
  3919.           d = *p;
  3920.           *p = '\0';
  3921.  
  3922.           for (flagno = 0; flag[flagno].template; flagno++)
  3923.             {
  3924.               if (! strcmp (r, flag[flagno].template))
  3925.             {
  3926.               flag_bits |= flag[flagno].set_bits;
  3927.               break;
  3928.             }
  3929.             }
  3930.  
  3931.           *p = d;
  3932.           if (! flag[flagno].template)
  3933.             goto try_shorter;
  3934.         }
  3935.           else
  3936.         goto try_shorter;
  3937.         }
  3938.  
  3939.       (*opcode->parms) (p, flag_bits);
  3940.       output_inst (start);
  3941.       return;
  3942.     }
  3943.  
  3944.     try_shorter:
  3945.     ;
  3946.     }
  3947.   /* It wasn't an instruction, but it might be a register alias of the form
  3948.      alias .req reg
  3949.      */
  3950.   q = p;
  3951.   while (*q == ' ')
  3952.     q++;
  3953.  
  3954.   c = *p;
  3955.   *p = '\0';
  3956.     
  3957.   if (*q && !strncmp (q, ".req ", 4))
  3958.     {
  3959.       int reg;
  3960.       if ((reg = arm_reg_parse (&str)) == FAIL)
  3961.     {
  3962.       char *r;
  3963.       
  3964.       q += 4;
  3965.       while (*q == ' ')
  3966.         q++;
  3967.  
  3968.       for (r = q; *r != '\0'; r++)
  3969.         if (*r == ' ')
  3970.           break;
  3971.  
  3972.       if (r != q)
  3973.         {
  3974.           int regnum;
  3975.           char d = *r;
  3976.  
  3977.           *r = '\0';
  3978.           regnum = arm_reg_parse (&q);
  3979.           *r = d;
  3980.           if (regnum != FAIL)
  3981.         {
  3982.           insert_reg_alias (str, regnum);
  3983.           *p = c;
  3984.           return;
  3985.         }
  3986.         }
  3987.     }
  3988.       else
  3989.     {
  3990.       *p = c;
  3991.       return;
  3992.     }
  3993.     }
  3994.  
  3995.   *p = c;
  3996.   as_bad ("bad instruction `%s'", start);
  3997. }
  3998.  
  3999. /*
  4000.  * md_parse_option
  4001.  *    Invocation line includes a switch not recognized by the base assembler.
  4002.  *    See if it's a processor-specific option.  These are:
  4003.  *    Cpu variants, the arm part is optional:
  4004.  *            -m[arm]1                Currently not supported.
  4005.  *            -m[arm]2, -m[arm]250    Arm 2 and Arm 250 processor
  4006.  *            -m[arm]3                Arm 3 processor
  4007.  *            -m[arm]6, -m[arm]7      Arm 6 and 7 processors
  4008.  *            -m[arm]7dm              Arm 7dm processors
  4009.  *            -mall                   All (except the ARM1)
  4010.  *    FP variants:
  4011.  *            -mfpa10, -mfpa11        FPA10 and 11 co-processor instructions
  4012.  *            -mfpe-old               (No float load/store multiples)
  4013.  *            -mno-fpu                Disable all floating point instructions
  4014.  *    Run-time endian selection:
  4015.  *            -EB                     big endian cpu
  4016.  *            -EL                     little endian cpu
  4017.  */
  4018.  
  4019. CONST char *md_shortopts = "m:";
  4020. struct option md_longopts[] = {
  4021. #ifdef ARM_BI_ENDIAN
  4022. #define OPTION_EB (OPTION_MD_BASE + 0)
  4023.   {"EB", no_argument, NULL, OPTION_EB},
  4024. #define OPTION_EL (OPTION_MD_BASE + 1)
  4025.   {"EL", no_argument, NULL, OPTION_EL},
  4026. #endif
  4027.   {NULL, no_argument, NULL, 0}
  4028. };
  4029. size_t md_longopts_size = sizeof(md_longopts);
  4030.  
  4031. int
  4032. md_parse_option (c, arg)
  4033.      int c;
  4034.      char *arg;
  4035. {
  4036.   char *str = arg;
  4037.  
  4038.   switch (c)
  4039.     {
  4040. #ifdef ARM_BI_ENDIAN
  4041.     case OPTION_EB:
  4042.       target_big_endian = 1;
  4043.       break;
  4044.     case OPTION_EL:
  4045.       target_big_endian = 0;
  4046.       break;
  4047. #endif
  4048.  
  4049.     case 'm':
  4050.       switch (*str)
  4051.     {
  4052.     case 'f':
  4053.       if (! strcmp (str, "fpa10"))
  4054.         cpu_variant = (cpu_variant & ~FPU_ALL) | FPU_FPA10;
  4055.       else if (! strcmp (str, "fpa11"))
  4056.         cpu_variant = (cpu_variant & ~FPU_ALL) | FPU_FPA11;
  4057.       else if (! strcmp (str, "fpe-old"))
  4058.         cpu_variant = (cpu_variant & ~FPU_ALL) | FPU_CORE;
  4059.       else
  4060.         goto bad;
  4061.       break;
  4062.  
  4063.     case 'n':
  4064.       if (! strcmp (str, "no-fpu"))
  4065.         cpu_variant &= ~FPU_ALL;
  4066.       break;
  4067.  
  4068.     default:
  4069.       if (! strcmp (str, "all"))
  4070.         {
  4071.           cpu_variant = ARM_ALL | FPU_ALL;
  4072.           return 1;
  4073.         }
  4074.  
  4075.       /* Strip off optional "arm" */
  4076.       if (! strncmp (str, "arm", 3))
  4077.         str += 3;
  4078.  
  4079.       switch (*str)
  4080.         {
  4081.         case '1':
  4082.           if (! strcmp (str, "1"))
  4083.         cpu_variant = (cpu_variant & ~ARM_ANY) | ARM_1;
  4084.           else
  4085.         goto bad;
  4086.           break;
  4087.  
  4088.         case '2':
  4089.           if (! strcmp (str, "2"))
  4090.         cpu_variant = (cpu_variant & ~ARM_ANY) | ARM_2;
  4091.           else if (! strcmp (str, "250"))
  4092.         cpu_variant = (cpu_variant & ~ARM_ANY) | ARM_250;
  4093.           else
  4094.         goto bad;
  4095.           break;
  4096.  
  4097.         case '3':
  4098.           if (! strcmp (str, "3"))
  4099.         cpu_variant = (cpu_variant & ~ARM_ANY) | ARM_3;
  4100.           else
  4101.         goto bad;
  4102.           break;
  4103.  
  4104.         case '6':
  4105.           if (! strcmp (str, "6"))
  4106.         cpu_variant = (cpu_variant & ~ARM_ANY) | ARM_6;
  4107.           else
  4108.         goto bad;
  4109.           break;
  4110.  
  4111.         case '7':
  4112.           if (! strcmp (str, "7"))
  4113.         cpu_variant = (cpu_variant & ~ARM_ANY) | ARM_7;
  4114.           else if (! strcmp (str, "7dm"))
  4115.         cpu_variant = (cpu_variant & ~ARM_ANY) | ARM_7DM;
  4116.           else
  4117.         goto bad;
  4118.           break;
  4119.  
  4120.         default:
  4121.         bad:
  4122.           as_bad ("Invalid architecture -m%s", arg);
  4123.           return 0;
  4124.         }
  4125.     }
  4126.       break;
  4127.  
  4128.     default:
  4129.       return 0;
  4130.     }
  4131.  
  4132.    return 1;
  4133. }
  4134.  
  4135. void
  4136. md_show_usage (fp)
  4137.      FILE *fp;
  4138. {
  4139.   fprintf (fp,
  4140. "-m[arm]1, -m[arm]2, -m[arm]250,\n-m[arm]3, -m[arm]6, -m[arm]7, -m[arm]7dm\n\
  4141. \t\t\tselect processor architecture\n\
  4142. -mall\t\t\tallow any instruction\n\
  4143. -mfpa10, -mfpa11\tselect floating point architecture\n\
  4144. -mfpe-old\t\tdon't allow floating-point multiple instructions\n\
  4145. -mno-fpu\t\tdon't allow any floating-point instructions.\n");
  4146. #ifdef ARM_BI_ENDIAN
  4147.   fprintf (fp,
  4148. "-EB\t\t\tassemble code for a big endian cpu\n\
  4149. -EL\t\t\tassemble code for a little endian cpu\n");
  4150. #endif
  4151. }
  4152.  
  4153. /* We need to be able to fix up arbitrary expressions in some statements.
  4154.    This is so that we can handle symbols that are an arbitrary distance from
  4155.    the pc.  The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
  4156.    which returns part of an address in a form which will be valid for
  4157.    a data instruction.  We do this by pushing the expression into a symbol
  4158.    in the expr_section, and creating a fix for that.  */
  4159.  
  4160. static void
  4161. fix_new_arm (frag, where, size, exp, pc_rel, reloc)
  4162.      fragS *frag;
  4163.      int where;
  4164.      short int size;
  4165.      expressionS *exp;
  4166.      int pc_rel;
  4167.      int reloc;
  4168. {
  4169.   fixS *new_fix;
  4170.  
  4171.   switch (exp->X_op)
  4172.     {
  4173.     case O_constant:
  4174.     case O_symbol:
  4175.     case O_add:
  4176.     case O_subtract:
  4177.       new_fix = fix_new_exp (frag, where, size, exp, pc_rel, reloc);
  4178.       break;
  4179.  
  4180.     default:
  4181.       {
  4182.     const char *fake;
  4183.     symbolS *symbolP;
  4184.     
  4185.     /* FIXME: This should be something which decode_local_label_name
  4186.        will handle.  */
  4187.     fake = FAKE_LABEL_NAME;
  4188.  
  4189.     /* Putting constant symbols in absolute_section rather than
  4190.        expr_section is convenient for the old a.out code, for which
  4191.        S_GET_SEGMENT does not always retrieve the value put in by
  4192.        S_SET_SEGMENT.  */
  4193.     symbolP = symbol_new (fake, expr_section, 0, &zero_address_frag);
  4194.     symbolP->sy_value = *exp;
  4195.     new_fix = fix_new (frag, where, size, symbolP, 0, pc_rel, reloc);
  4196.       }
  4197.       break;
  4198.     }
  4199.  
  4200.   return;
  4201. }
  4202.  
  4203. /* A good place to do this, although this was probably not intended
  4204.  * for this kind of use.  We need to dump the literal pool before
  4205.  * references are made to a null symbol pointer.  */
  4206. void
  4207. arm_after_pass_hook (ignore)
  4208.      asection *ignore;
  4209. {
  4210.   if (current_poolP != NULL)
  4211.     {
  4212.       subseg_set (text_section, 0); /* Put it at the end of text section */
  4213.       s_ltorg (0);
  4214.       listing_prev_line ();
  4215.     }
  4216. }
  4217.  
  4218. void
  4219. arm_start_line_hook ()
  4220. {
  4221.   last_label_seen = NULL;
  4222. }
  4223.  
  4224. void
  4225. arm_frob_label (sym)
  4226.      symbolS *sym;
  4227. {
  4228.   last_label_seen = sym;
  4229. }
  4230.